On Save Stored Procedures¶
When Editable Table records are added, edited or deleted, you can wire up a set of stored procedures to run on the Before Save event and the After Save event:
Stored procedure parameters¶
A custom stored procedure used here will be passed provided it has the one required argument: @json. This is a packet of JSON that represents what the event is working on and has the following structure:
{
action: "",
catalog: "",
datasource: "">,
deletes: [{columnName: "value"}],
editableTableId: 0,
editableTableName: "",
eventType: "",
inserts: [{columnName: "value"}],
serverTimeLocal: "",
serverTimeUTC: "",
updates: [{columnName: "value"}],
userId: ""
}
Property | Type | Description |
---|---|---|
action | string | The Table Editor action being performed - one of Create or Update or Delete |
catalog | string | The name of the database that is being used |
datasource | string | The name of the datasource that is being used |
deletes | array | The array of records being deleted |
editableTableId | int | The database ID of the Editable Table that caused the event |
editableTableName | string | The name of the Editable Table that caused the event |
eventType | string | The Table Editor onSave event being triggered - one of AfterSave or BeforeSave |
inserts | array | The array of records being created |
serverTimeLocal | string | The server local time of the event in ISO 8601 Notation (including timezone offset) |
serverTimeUTC | string | The UTC time of the event in ISO 8601 Notation |
updates | array | The array of records being updated |
userId | string | The login ID of the user performing the action from the CALUMOUsers table |
You should use the following signature for your stored procedures:
Example¶
CREATE PROC <name>
@json varchar(max)
AS
GO
Stored procedure return¶
Inside custom stored procedures, there are ways to feedback to your users about what has taken place.
Success message¶
Only valid for AfterSave events, return a message to users to let them know the action was successful.
SELECT 'AWESOME - It Worked!!'
Throw an error¶
Use the T-SQL THROW directive without a following CATCH block to send an error back to the user and terminate the action.
throw 51000, 'Could not validate the customer', 1
RAISERROR¶
Use the T-SQL RAISERROR directive to send an error back to the user and terminate the action.
RAISERROR('Could not validate the customer', 16, 1)
Simple error return¶
Use a simple select statement in the following format to send an error back to the user and terminate the action.
SELECT 'ERROR', 'This is the error to show the user'
Cell by cell error return¶
Create a data table result that returns:
Column Number | Detail |
---|---|
COLUMN 1 | KEY of the record in error |
COLUMN 2 | Column name on the record that has the error |
COLUMN 3 | Error to return for this KEY/Column combination |
This will appear as cell errors in the correct record and column.
SELECT 1029, 'CustomerName', 'The customer name must not contain the # character'
UNION ALL Select 1029, 'CustomerState', 'The customer state must not be empty'
UNION ALL Select 1029, 'CustomerLicenseCount', 'The license count must be greater than 0'