Share via


Scripts.ReplaceStoredProcedureAsync Method

Definition

Replaces a StoredProcedureProperties in the Azure Cosmos service as an asynchronous operation.

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.Scripts.StoredProcedureResponse> ReplaceStoredProcedureAsync (Microsoft.Azure.Cosmos.Scripts.StoredProcedureProperties storedProcedureProperties, Microsoft.Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReplaceStoredProcedureAsync : Microsoft.Azure.Cosmos.Scripts.StoredProcedureProperties * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.Scripts.StoredProcedureResponse>
Public MustOverride Function ReplaceStoredProcedureAsync (storedProcedureProperties As StoredProcedureProperties, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of StoredProcedureResponse)

Parameters

storedProcedureProperties
StoredProcedureProperties

The Stored Procedure to replace

requestOptions
RequestOptions

(Optional) The options for the stored procedure request.

cancellationToken
CancellationToken

(Optional) CancellationToken representing request cancellation.

Returns

A Task containing a StoredProcedureProperties.

Exceptions

If storedProcedureProperties is not set.

This exception can encapsulate many different types of errors. To determine the specific error always look at the StatusCode property. Some common codes you may get when creating a Document are:

StatusCodeReason for exception
404NotFound - This means the resource you tried to delete did not exist.

Examples

This examples replaces an existing stored procedure.

//Updated body
string body = @"function AddTax() {
    var item = getContext().getRequest().getBody();

    // Validate/calculate the tax.
    item.tax = item.cost* .15;

    // Update the request -- this is what is going to be inserted.
    getContext().getRequest().setBody(item);
}";

Scripts scripts = this.container.Scripts;
StoredProcedureResponse response = await scripts.ReplaceStoredProcedureAsync(new StoredProcedureProperties("testTriggerId", body));

Applies to