
- 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-06-2024 11:12 AM
Hi @Community Alums
The error says that your endpoint does not exist. Since you are doing a put I would say that the part that does not exist is the sys_id. Meaning there is no location record in the second instance with the same sys_id as the record in the first instance.
Check the logic with a sys_id of a location record in the second instance.
Regards,
Niklas

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 11:41 AM
The URL is correct, I have verified that by copying it into a secondary browser and it's fine.
The sys_Id is identicle on both of them. I'm using a REST Message that has the GET/POST/PUT in them and the POST is Working perfect, the GET is working perfect so something else is wrong with the PUT statement

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 11:51 AM
Info MessageResponse Body: {"error":{"message":"Method not Supported","detail":"PUT method not supported for API"},"status":"failure"}
I am now getting this
- 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'),