> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blinkops.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ServiceNow Webhook Event

ServiceNow Business Rules allow you to respond to insert, query, update, and delete operations on ServiceNow tables. You can configure a Business Rule with a JavaScript script to send webhook events to Blink whenever the rule is triggered.

## Configuring a ServiceNow Webhook

<Info>
  This guide explains how **Admins** can create a business rule. Non-admin users must be assigned the `business_rule_admin` role to create business rules.

  <img src="https://mintcdn.com/blinkops-2/4jJzHLYX9WcCQdrG/img/servicenow/Webhook/business_rule_role.png?fit=max&auto=format&n=4jJzHLYX9WcCQdrG&q=85&s=4467a3416729b070064af7d11e988466" alt="business_rule_role" width="3800" height="1910" data-path="img/servicenow/Webhook/business_rule_role.png" />

  For more information on assigning roles to users, please visit our [documentation](https://docs.blinkops.com/docs/integrations/servicenow#assign-roles-to-user).
</Info>

### Creating the Business Rule

1. In the navigation filter (under the `All` tab), search for **studio** and click **Studio** under **System Applications**.

   <img src="https://mintcdn.com/blinkops-2/iMIEUHxdi6cXuLI5/img/servicenow/Webhook/studio.png?fit=max&auto=format&n=iMIEUHxdi6cXuLI5&q=85&s=6a2e530a1fb5d298c2060d07d759571c" alt="Studio_View" width="3816" height="1914" data-path="img/servicenow/Webhook/studio.png" />

2. Select an **application** (or create a new one) to associate the Business Rule with. For more information on creating new applications, please visit [ServiceNow's Documentation](https://developer.servicenow.com/dev.do#!/learn/courses/xanadu/app_store_learnv2_buildneedit_xanadu_build_the_needit_application/app_store_learnv2_buildneedit_xanadu_create_the_needit_application_and_application_files/app_store_learnv2_buildneedit_xanadu_creating_an_application).

   <img src="https://mintcdn.com/blinkops-2/iMIEUHxdi6cXuLI5/img/servicenow/Webhook/select_app.png?fit=max&auto=format&n=iMIEUHxdi6cXuLI5&q=85&s=ce0c5c60e3418338641d48c166b930d6" alt="select_app" width="3836" height="1916" data-path="img/servicenow/Webhook/select_app.png" />

3. On the next page, click **Create Application File**.

   <img src="https://mintcdn.com/blinkops-2/iMIEUHxdi6cXuLI5/img/servicenow/Webhook/create_app_file.png?fit=max&auto=format&n=iMIEUHxdi6cXuLI5&q=85&s=7b220b2956dd45b551f60eac216effd1" alt="create_app_file" width="3834" height="1848" data-path="img/servicenow/Webhook/create_app_file.png" />

4. In the new file form, search for **Business Rule** and click **Create**.

   <img src="https://mintcdn.com/blinkops-2/iMIEUHxdi6cXuLI5/img/servicenow/Webhook/create_business_rule.png?fit=max&auto=format&n=iMIEUHxdi6cXuLI5&q=85&s=d2e5d291094f97eae628832eb2f1c424" alt="create_business_rule" width="2244" height="1450" data-path="img/servicenow/Webhook/create_business_rule.png" />

5. Configure the new rule's references settings:

   1. **Name the Rule**: Enter a descriptive name that reflects the rule’s purpose.

   2. **Select the Target Table**: Choose the table the rule will apply to.

   3. **Enable the Rule**: Check both **Active** and **Advanced**.

   4. **Set When to Run**:
      * Choose **After** to run the rule once the record changes are saved.
      * Enter the **Order** value (leave at `100` unless you need a custom sequence).
      * Select the operations (Insert, Update, Delete, Query) that should trigger the rule.

   <img src="https://mintcdn.com/blinkops-2/iMIEUHxdi6cXuLI5/img/servicenow/Webhook/new_business_rule.png?fit=max&auto=format&n=iMIEUHxdi6cXuLI5&q=85&s=2a57cf636f9ce7e06cc3d4a6f13cd5f2" alt="new_business_rule" width="3820" height="1910" data-path="img/servicenow/Webhook/new_business_rule.png" />

6. Under the **Advanced** section, insert a JavaScript script that will trigger Blink's workflow. Click on the **Save** icon and then **Submit**.

   <img src="https://mintcdn.com/blinkops-2/iMIEUHxdi6cXuLI5/img/servicenow/Webhook/rule_script.png?fit=max&auto=format&n=iMIEUHxdi6cXuLI5&q=85&s=929c8773c9ce6e12c6cb4fe80bb1f208" alt="rule_script" width="3822" height="1846" data-path="img/servicenow/Webhook/rule_script.png" />

   <br />

   **Here's an example of a rule script that triggers a workflow in Blink:**

   <Info>
     **Important to Note**:

     1. Make sure to copy the full Webhook URL of the workflow you want to trigger in Blink.

          <img src="https://mintcdn.com/blinkops-2/iMIEUHxdi6cXuLI5/img/servicenow/Webhook/webhook_url.png?fit=max&auto=format&n=iMIEUHxdi6cXuLI5&q=85&s=537bbeb8ff6cc9bc63238ee33f3e5de9" alt="webhook_url" width="3834" height="1918" data-path="img/servicenow/Webhook/webhook_url.png" />

     2. Replace the `https://your-real-webhook-url` placeholder in the script with the copied URL.

     3. In the `payload` variable, add the table columns you want to send when the webhook is triggered, in the following format:
        `col_name: current.getValue('col_name')`.
   </Info>

   ```javascript theme={"dark"}
   (function executeRule(current, previous) {

       var r = new sn_ws.RESTMessageV2();
       r.setEndpoint('https://your-real-webhook-url');
       r.setHttpMethod('POST');
       r.setRequestHeader('Content-Type', 'application/json');

       var payload = {
           sys_id: current.getValue('sys_id'),
           sys_created_on: current.getValue('sys_created_on')
       };

       r.setRequestBody(JSON.stringify(payload));

       try {
           var response = r.execute();
       } catch (ex) {
           gs.error('Webhook call failed: ' + ex.message);
       }

   })(current, previous);
   ```

**The following is an example of an event payload received in Blink:**

<img src="https://mintcdn.com/blinkops-2/iMIEUHxdi6cXuLI5/img/servicenow/Webhook/event.png?fit=max&auto=format&n=iMIEUHxdi6cXuLI5&q=85&s=e70a8289220465d01a8666eb4ef00d7c" alt="event" width="3840" height="1930" data-path="img/servicenow/Webhook/event.png" />
