The Pre save script is invoked before a resource is saved and is used to validate the submitted resource, perform any restriction and permission checks, and perform any last-minute changes to the current resource. A Pre save script can live on in the following resources: integration, flow, import, export, and connection. Whenever the resource is saved, it first goes through this script.
Warning
The Pre save script cannot be attached to a resource via the Celigo platform interface. To attach the script to a resource, you’ll need to use Postman or another third-party system and the Celigo integrator.io APIs.
/* * preSave function stub: * * The name of the function can be changed to anything you like. * * The function will be passed one 'options' argument that has the following fields: * 'newResource' - the resource being saved. * 'oldResource' - the resource last saved. * 'sandbox' - boolean value indicating whether the script is invoked for sandbox. * * The function needs to return the newResource object to save. * Throwing an exception will signal an error. */ function preSave (options) { return options.newResource; }
In this example, the pre save script was used to set the value of a field map based on whether it was in a production or sandbox environment. Add it to a resource by adding this snippet to the root:
"preSave": { "function": "yourScriptFunction", "_scriptId": "yourScriptId" }
Script example:
function preSave(options) { options.newResource.settings = options.newResource.settings || {}; options.newResource.settings.sandbox = options.sandbox; return options.newResource; }
Comments
Article is closed for comments.