- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 10:23 AM
I have created an after update business rule that works with a PUT Rest Message endpoint. I have tested this between two instance and two PDIs and I'm getting the same problem
I have verified that the SYS ID's match (as I used POST message to get this across to the other instance. I'm kind of stuck here. I'm trying to update the record on the second system via PUT or PATCH and nothing is workink
Here is the code for the business rule:
Table: cmn_location
Active, Advanced:
When to run: After - update - order 100
Advanced tab script:
(function executeRule(current, previous /*null when async*/) {
try {
var r = new sn_ws.RESTMessageV2('dev266487_contract', 'CMNLocation_put');
var body = {
"name": current.getDisplayName('name'),
"contact": current.getValue('contact'),
"state": current.getDisplayValue('state'),
"city": current.getDisplayValue('city'),
"street": current.getDisplayValue('street')
};
var corID = current.getValue('sys_id');
r.setEndPoint('https://dev266487.service-now.com/api/now/table/cmn_location/'+corID);
r.setRequestBody(JSON.stringify(body));
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.addInfoMessage("Response Body: " + responseBody);
gs.addInfoMessage("httpStatus: "+httpStatus);
gs.addInfoMessage("SYSID: " + corID);
}
catch(ex) {
var message = ex.message;
}
})(current, previous);
Does anyone see anything wrong with this. I also have tested the REST user with Admin Rights (just to make sure ACL's are not the issue).
Please help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 03:28 PM - edited 08-06-2024 03:47 PM
Hi @Community Alums - Set the endpoint to `https://dev266487.service-now.com/api/now/table/cmn_location/${sys_id}` in the HTTP method, then add a variable substitution with the name sys_id.
(function executeRule(current, previous /*null when async*/) {
try {
var r = new sn_ws.RESTMessageV2('dev266487_contract', 'CMNLocation_put');
r.setStringParameterNoEscape('sys_id', current.getUniqueValue());
var body = {
"name": current.getDisplayValue('name'),
"contact": current.getValue('contact'),
"state": current.getDisplayValue('state'),
"city": current.getDisplayValue('city'),
"street": current.getDisplayValue('street')
};
//var corID = current.getValue('sys_id');
//r.setEndPoint('https://dev266487.service-now.com/api/now/table/cmn_location/' + corID);
r.setRequestBody(JSON.stringify(body));
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.addInfoMessage("Response Body: " + responseBody);
gs.addInfoMessage("httpStatus: " + httpStatus);
} catch (ex) {
var message = ex.message;
}
})(current, previous);
Also, there is an error in your JSON (fixed above):
"name": current.getDisplayName('name'),
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 05:09 AM
Thank you x 10000000! I really appreciate the guidance on this. Awesome!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 05:17 AM
@Community Alums ,
Have a look at my clip, it will show you how the REST-API works.