- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 01:58 PM
I am trying to activate a POST request whenever a business rule is activated, because I want to send the contents of a ticket to my local database whenever a new ticket is made.
I have tried to add this code just to see if I can get the 2 servers talking (obviously this would not send the ticket contents):
(function executeRule(current, previous /*null when async*/) {
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "https://my_ip:5000/todos", true);
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.send(JSON.stringify({ "todo_id": 10, "task":"FROM SNOW :D"}));
})(current, previous);
as a script in the advanced section of the business rule with a blank condition but it does not run with the business is activated. I have a message being sent to myself, so I know the rule is being activated but my server does not hear the POST.
I can runt the 4 middle lines in my firefox console and they work.
For more context if necessary (both of these questions are mine):
python - Adding a curl request into a serviceNow business rule (javascript) - Stack Overflow
python - Calling flask via javascript run on an https external site - Stack Overflow
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 10:30 PM
Hi Matthew,
As Sirni mentioned, the WIki link above is a very good resource.
If you want to send an outbound message its better to use the provided ServiceNow features. So you can :
1) Choose wether you want REST or SOAP and create the appropriate outbound message in the "System Web Services" App of your instance
2) After you create the message you can click on it, and go to 'HTTP Methods' at the bottom and click one of them. Then click 'Preview Script Usage' and it will give you the code you need to use this messaeg in the Business Rules.
The script displayed can be used in your Business Rules now.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 02:09 PM
Did you setup the outbound message first?
Check 4.1 in below URL.
Outbound REST Web Service - ServiceNow Wiki
This give you the script to be used in Business Rules
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2017 09:52 AM
The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here:
Outbound REST Web Service
Visit http://docs.servicenow.com for the latest product documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 10:30 PM
Hi Matthew,
As Sirni mentioned, the WIki link above is a very good resource.
If you want to send an outbound message its better to use the provided ServiceNow features. So you can :
1) Choose wether you want REST or SOAP and create the appropriate outbound message in the "System Web Services" App of your instance
2) After you create the message you can click on it, and go to 'HTTP Methods' at the bottom and click one of them. Then click 'Preview Script Usage' and it will give you the code you need to use this messaeg in the Business Rules.
The script displayed can be used in your Business Rules now.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2017 08:08 AM
Thanks for the help.
I am trying to make a put call that has the same functionality as:
curl http://[my_ip]:5000/todos/ -X GET -v
I first start at this page:
Then I click submit
And then I make the GET call here:
But when I hit test I keep getting a failed response.
Even if I just click the endpoint link as written in the HTTP Method chrome will get a valid response; it will print the JSON from my server.
Am I missing a step?