For integration move record Servicenow to another application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 05:44 AM
Hi team/ @Ankur Bawiskar ,
For integration we want to move incident records from Servicenow to another 3rd party application, i.e all details of incident records will be move to 3rd party application & delete from Servicenow table.
We created schedule job through that we want to achieve it for now single record.. So require some support for that. Can you please check & validate below script we wrote ? is it correct script or modify something. Please assist on it.
var active = crerec.active;
var descrip = crerec.description;
var shortdescr = crerec.short_description;
var crerec = new GlideRecord('incident');
crerec.addEncodedQuery('numberLIKEINC36XXX');
crerec.query();
if(crerec.next()){
active = crerec.active;
descriptio = crerec.description;
shortdescr = crerec.short_description;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 05:57 AM
Hi @abirakundu23,
The JavaScript code you provided is a good start, but there are a few things you can do to improve it.
First, you should use a variable name that is more descriptive than crerec.
For example, you could use incidentRecord.
Second, you should use a more specific query than numberLIKEINC36XXX.
This query will return all incidents whose number starts with INC36, but you may only want to return incidents that are currently active. You can do this by adding the active=true filter to your query.
Third, you should use a try/catch block to handle any errors that may occur. For example, if the REST API call fails, you can catch the error and log it.
Try it like this:
var incidentRecord = new GlideRecord('incident'); incidentRecord.addEncodedQuery('numberLIKEINC36XXX AND active=true'); incidentRecord.query(); try { if (incidentRecord.next()) { var active = incidentRecord.active; var description = incidentRecord.description; var shortDescription = incidentRecord.short_description; var r = new sn_ws.RESTMessageV2('ServiceNow', 'POST'); //r.setRequestBody(input); var response = r.execute(); var responseBody = response.getBody(); var httpStatus = response.getStatusCode(); gs.log("Incident Response code: " + httpStatus); if (httpStatus == 201) { incidentRecord.deleteRecord(); } } } catch (error) { gs.log("Error: " + error.message); }
I hope this helps!
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.