- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 11-15-2020 11:54 AM
Hi
Let's assume you want to remotely update Short Description of your favorite Incident in ServiceNow instance. How to approach this by leveraging low-code development technique and Rest API? Please see below few very simple steps.
1) Create sub-flow in Flow Designer (instead of long/complex javascript code in Scripted REST API).
For demo purposes, I made this subflow in "global" scope and named it as "test".
Define Input' s (Incident ID, Incident Description) for SubFlow
Search (look up) for the record in Incident table, where Number is Incident ID (supplied as an Input, see above)
Update Incident Short Description with a new Incident description (supplied as an input, see above).
In overall, sub-flow should look like:
2) Create Scripted RESTAPI with resource
Go to Scripted REST APIs, create new REST API ( I named it as "UpdatingINC") and make a new Resource there
Few notes:
HTTP method = POST (this is important)
Relative path (as API expects two parameters to submit):
/updating/{incidentID}/{incidentDescr}
Script, which reads two parameters and passes these parameters to the subflow (global.test):
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
try {
var pathParamsVar = request.pathParams;
var inputs = {};
inputs['incident_id'] = pathParamsVar.incidentID;
inputs['incident_decription'] = pathParamsVar.incidentDescr;
sn_fd.FlowAPI.getRunner().subflow('global.test').inBackground().withInputs(inputs).run();
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
})(request, response);
3) Finally send HTTP POST to Rest API of your instance, to test how it works
I used my Linux server in the cloud to make such a call (updating a short description of incident INC0010112to "RestAPI-Forever" :
curl -X POST "https://devXXXXX.service-now.com/api/96330/updatinginc/updating/INC0010112/RestAPI-Forever" -H "accept: application/json" -u "abel.tuter":"abel_password"
Of course, abel.tuter should have a role web_service_admin applied first !!
Hope it helps!
- 5,040 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you for sharing this innovative approach to scripted REST API. Flow designer adds a lot of built-in traceability that is useful for debugging therefore it's really interesting to be able to take advantage of it inside a scripted REST API.