executeStoredProcedure
This function allows you to execute a stored procedure in the database. It can be used for operations that need to be performed directly in the database, such as complex data manipulations, bulk operations, or administrative tasks.
Syntax
app.executeStoredProcedure(procedureName, parameterJson, cmdOptions)
Parameters
Parameter | Type | Description |
---|---|---|
procedureName | String | The name of the stored procedure to execute |
parameterJson | Object | (Optional) An object with parameters to pass to the stored procedure |
cmdOptions | Object | (Optional) Configuration options for the execution |
cmdOptions.timeout | Number | (Optional) Timeout for the SQL request in seconds (default: 30) |
cmdOptions.connectionKey | String | (Optional) A key to a custom settings entry with the connection string to an external MSSQL database |
Return Value
The function returns the result of the stored procedure execution, which could be:
- Success/failure status
- Data modified count
- Any output parameters or result sets defined by the stored procedure
Examples
Example 1: Simple stored procedure execution:
// Execute a stored procedure with no parameters
app.executeStoredProcedure("UpdateInventoryLevels");
Example 2: Executing a stored procedure with parameters:
// Execute a stored procedure with input parameters
app.executeStoredProcedure("ProcessOrder", {
orderId: 12345,
statusCode: "SHIPPED",
updateDate: "2025-04-16"
});
Example 3: Executing a stored procedure with custom timeout:
// Execute a procedure that might take longer with a 45-second timeout
app.executeStoredProcedure("GenerateMonthlyReport", {
reportMonth: 4,
reportYear: 2025,
includeDetails: true
}, {
timeout: 45
});
Example 4: Executing a stored procedure with a custom connection:
// Execute a stored procedure on a specific external database connection
app.executeStoredProcedure("SyncExternalCustomers", {
lastSyncDate: "2025-04-01"
}, {
connectionKey: "externalPartnerDb"
});
Notes
- The stored procedure must be properly defined in the database
- Parameter names in the
parameterJson
object must match parameter names in the stored procedure - In addition to explicitly provided parameters, the current form's field values are automatically available in the stored procedure
- For stored procedures that return data, consider using
queryStoredProcedure
instead - Error handling should be implemented when executing stored procedures with potential failures