- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2023 09:43 AM - edited ‎02-13-2023 10:34 PM
Hello all,
I created a REST Message to create and update the record of SN instance1 to SN instance2.
Information I am storing in instance2 including instance1.table.record.sys_id and I am attempting to Update the record in instance2 based on sys_id as a parameter.
My POST is working fine but PUT is giving me an error msg: {"error":{"message":"Method not Supported","detail":"PUT method not supported for API"},"status":"failure"}
Could you help to advise what could be the mistake?
*note:sys_id is stored as u_correlation_id in instance2
REST Message:
PUT
AFTER UPDATE business rule
(function executeRule(current, previous /*null when async*/ ) {
var body = {
"u_organization": gs.getProperty('instance_name'),
"u_name": current.name.toString(),
};
try {
var r = new sn_ws.RESTMessageV2('my Integration', 'Default PUT');
r.setStringParameterNoEscape('u_correlationid',current.getUniqueValue());
r.setRequestBody(JSON.stringify(body));
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
} catch (ex) {
var message = ex.message;
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2023 05:53 AM
Thank you Kirby. I need the sys_id to be dynamic and I've managed to achieve what I wanted with staging table and transform map.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2023 11:42 PM - edited ‎02-13-2023 11:46 PM
Hi @tsoct ,
I believe that should look something like r.setEndpoint('https://xx.service-now.com/api/now/table/u_license/' + u_correlationid)'.
Passing in sysparm_query is ideally for GET as you are fetching data and not applicable to PUT/POST.
To add, you may also try REST API Explorer in your instance 2 to easily build your api url. So you dont have to continuously edit and test your business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2023 11:46 PM
Hi Kirby,
u_correlationid is a field in SNinstance2. While I am now using the sys_id from SNinstance1 to query in SNinstance2, r.setEndpoint('https://xx.service-now.com/api/now/table/u_license/' + u_correlationid)' doesn't seems to work...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2023 11:51 PM
Ok. So the sys_id are different right? If thats the case, you need two API calls.
1. Fetch the record extract sysid from instance 2.
2. Send PUT api call to update passing in the extracted sys_id from 1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2023 11:57 PM
This is my first time building an API. Would you mind sharing how should I fetch the sysid from instance 2?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2023 12:04 AM - edited ‎02-14-2023 12:07 AM
Just open the u_license record and right click on the burger icon(3 lines) copy sys_id.
Using REST Explorer: