Workaround: Updating an Incident using Webhooks
6 min
scenario this is a proof of concept for a workaround to enable you to use action types other than insert object with the initial webhooks implementation this is a complex workaround for advanced users, so if you can wait for the full implementation in a future release of , we encourage you to do so we will use a webhook to update the description for an incident record; we can do this automatically by using a staging business object and triggered actions important during testing, using triggered actions to automatically delete the staging business object didn't work hence you must manually delete staging records that have the done field set to true , or set up an action/workflow to run on schedule to do this for you prerequisites to recreate this example, you need to be an administrator, and have access to an external api tool such as postman how it works using postman or a similar tool, send a request via the webhook to the webhookstaging business object this request carries the recid of the incident record to be updated, as well as the new description, all in the request body receipt of the request causes the webhookstaging business object to run the create a new record action (called create staging in our example) that creates a new record, and puts all the data from the request body into the datafield in the same action ( create a new record ), an expression extracts the recid from the request body and puts it into an id field in the newly created webhookstaging object record the creation of the webhookstaging record causes a triggered action to run the update a record action that changes the value in the done field from false to true simultaneously, the run for child action is configured to run the update a record action against the incident record which takes the description out of the datafield and updates the description field in the incident record create the webhookstaging business object in , create a business object called webhookstaging create the following extra fields in the business object field display name type nullable stored datafield datafield text(max) selected selected done done boolean selected selected recordid recordid link selected selected click on relationships for the webhookstaging business object and set up the relationship between the staging business object and the incident business object as shown the staging business object is related to the incident business object (zero or many contained in zero or one ), storing the incident recid in the link field create the "createstaging" action in itsm createstaging is based on a create a new record action block and is used to create a staging object to dump the data sent to the webhook into, as well as the recid of the record to update open the graphical action designer see using the graphical action designer (gad) docid 2wq6ihun2zxir21ea3m7g tip you can use the classic action designer if you prefer create a new block using the update variables and stored values action block type this block updates the stored values and variables used in your action for more help see update stored values and variables quick action docid\ dofjmmkz8 omktccl485k configure the update variables and stored values action block to store the data given to the webhook endpoint in the required variable webhookbody edit the values as follows field value variable type variable name webhookbody data type json value {} create a new block using the create a new record action block type, and attach it to the update variables and stored values action block edit the create a new record block for each field, create an expression using the simplified expression editor to use the variable to populate that particular field the datafield and recordid fields are populated from the webhook data for recordid , the expression retrieves a value for the json path and uses it to populate the field use this expression to populate the recordid field $(jsonpathvalue(variable("webhookbody"), "$ incidentrecid")) the target business object (incident) is set in the recordid category field for help, see using the simplified expression editor docid\ aycvgwq xaxop0ofpgl9h save your action as create staging create the webhook in itsm create a webhook to trigger the create a new record action to put webhook data and the recid into the staging business object webhookstaging in the settings menu, click on webhooks manager in the build section the webhooks manager opens click add a webhook enter this information into the fields field value name update incident description description this webhook creates a staging object, which in turn runs a triggered action to update the related incident's description endpoint extension updateincident note the endpoint extension is case sensitive full endpoint https //{tenant url}/api/rest/webhooks/execute?extension=updateincident select business object webhookstaging (webhookstaging) select action createstaging (composite action) click save a confirmation message appears saying webhook successfully created your webhook appears in the list and is enabled by default create the update a record action the update a record action runs from the run for child action, and updates the description of the target object by taking the data dumped into the related webhookstaging object open the graphical action designer see using the graphical action designer (gad) docid 2wq6ihun2zxir21ea3m7g create a new block using the update description block type name it update a record edit the update a record block create an expression using the simplified expression editor to take the content from the datafield and parse it into the incident description field use this expression $(jsonpathvalue(\[webhookstaging# webhookstaginassocincident]datafield, "$ description")) set up the triggered actions in itsm set up two triggered actions against the webhookstaging business object one of these has an action as part of it based on run for child with the webhookstaging business object open, click business rules click triggered actions create two triggered actions as follows tip click next to move to the next screen to find all the fields shown in the tables for each triggered action trigger 1 value name set done to true object event on insert action that will be executed by this trigger action update object target object field done = $(true) overwrite = selected trigger 2 value name trigger incident update object event on insert action that will be executed by this trigger run for child run for child configuration child object and relationship webhookstagingassocincident add new > action to run update description the run for child action is triggered on creation of the staging object, and runs the third action using the relationship between the staging business object and the target record create the triggered action using the following fields field value name run for child relationship webhookstagingassocincident action to run update description click save sending a request to update a record description this is the target incident record with the description that we want to update using postman or a similar tool, send the recid of the target incident and the new description in the request click send in postman click refresh in the incident record page the description field has been updated with your new value
