How do I use the API to create a Business Rule containing a custom script?

zterlizz
Giga Contributor

I found this great resource that uses a Business Rule to call a custom API endpoint over REST: https://www.transposit.com/devops-blog/itsm/creating-webhooks-in-servicenow/

 

I set up a Business Rule on my ServiceNow account to execute my custom script after a table is updated, but now I need to scale up my solution to automate the process for other ServiceNow customers. ServiceNow has great documentation for Business Rules (https://docs.servicenow.com/bundle/sandiego-application-development/page/script/business-rules/conce...) but I do not see anything about dynamically creating a new rule. Does anyone know how to programmatically create a Business Rule using the ServiceNow API?

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

Capture the business rule in an update set, export it and provide the file to whomever you like. They can import the update set, preview and commit it. (The same can be done with just an xml export of the BR).  I can't speak on using REST, doesn't seem appropriate to use to make configuration changes to an instance.

View solution in original post

6 REPLIES 6

Mike_R
Kilo Patron
Kilo Patron

If i read this right, you want to use a rest api from an external system to create a business rule in ServiceNow. Can you confirm if that's what you're looking for or is it something different? 

zterlizz
Giga Contributor

Thank you for your reply. My intention is to use the ServiceNow API to create a Business Rule. I would also accept any solution that allows the creation of a Business Rule programmatically so that a user must only supply my third-party API authorization to their ServiceNow account, and my solution could automatically configure a Business Rule to send my third-party API updates when data is changed for some table on the users' ServiceNow account.

Bert_c1
Kilo Patron

Capture the business rule in an update set, export it and provide the file to whomever you like. They can import the update set, preview and commit it. (The same can be done with just an xml export of the BR).  I can't speak on using REST, doesn't seem appropriate to use to make configuration changes to an instance.

zterlizz
Giga Contributor

Wow, Update Sets is a great feature for this purpose. Do you know if ServiceNow has a way to programmatically import an Update Set?

 

For context, I allow users to connect their ServiceNow account to my third-party tool using a custom-made ServiceNow module that can generate an authentication token to allow my tool to safely connect over REST. I would like to add the feature for my tool to automatically setup and receive updates using Business Rules when a specific table experiences changes. If there is a way to automatically create and destroy the Business Rule, even just using my existing custom ServiceNow module, then I would be interested in learning more about it!