- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 09:03 AM - edited 03-24-2025 09:50 AM
Hello Everyone,
I am working on integration where ServiceNow makes call to 3rd party tool using REST Message and we have a GET method defined bring incident data in ServiceNow. We have established a connection and we are getting the data in below format. Now the problem is, 1) The field value (key) contains spaces in it, how to process that data and insert into ServiceNow incident table 2) We have 60000 records to be processed, how all can be processed using pagination, looking for script.
Note: there are fields with spaces: ex. "Assignee Login ID" and some field has colon in it "Test: "
Payload received (receiving the data with offset=2000)
{"entries":[
{
"values": {
"Entry ID": "INC000000000623",
"Submitter": "gash.te.net",
"Ebond_ValidateFlag": null,
"Submit Date": "2015-11-03T19:36:06.000+0000",
"Ebond_WorkLogID": null,
"Assignee Login ID": "gash.te.net",
"z1D_SV_IA_Organization": null,
"Last Modified By": "AR_ESCALATOR",
"Last Modified Date": "2024-09-20T02:40:37.000+0000",
"Status": "Closed",
"Short Description": ".",
"z1D_AssigneeManagerLogin": null,
"z1D_SV_IA_Region": null,
"Notifier Listening": "Not Listening",
"z1D_SV_IA_Site": null,
"z1D_DefaultCompanyAction": null,
"z1D_SkipIfSmartITInstalled": null,
"z1D Status Integer Parm02": null,
"Vendor Name": null,
"z1D Status Integer Parm01": null,
"z1D_SV_IA_Department": null,
"z1D_SV_IsFormDirty": null,
"z1D_AssociationType02": null,
"z1D_SV_IA_Company": null,
"Owner Support Company": "IT Security",
"Owner Group ID": "SGP000000001025",
"z1D_SV_IA_SiteGroup": null,
"z1d_SV_AIOPs_NotImpacted": null,
"Owner Group": "Security",
"Impact_OR_Root": null,
"z2AF_Act_Attachment_2": null,
"z1D_googleMapApiKey": null,
"Test:NTT:SNOW_SYSID": null,
"Test:NTT:SNOW_FLAG": null,
"z2AF_SV_DD_Attachment": null,
"z1D_AssigneeManager": null,
"Assignee Groups": "1000000020;",
"z1D_DefaultCompanyInteger": null,
"SV_Password_MCSM": "***",
"z1D Char16": null,
"z1D Date01": null,
"z1D_SV_SetDetailedDescription_Assignment_Activity": null,
"z1D_SV_SetDescription_Assignment_Activity": null,
"z1D_SV_SetMessageID_Assignment_Activity": null,
"z1D_PreviousAssignedCompany": "Test
"z2AF_Act_Attachment_1": null,
"status_reason2": null,
"Assigned Group Shift Name": null,
"Shifts Flag": null,
"InstanceId": "IDHAA5V0G7RG3ANXJH5H1BB94O5537",
"z1D_Assignee_Email": null}
]}}],
"_links": {
"self": [
{
"href": "/api/arsys/v1.0/entry/HPD:Help%20Desk/INC000000000623"
}
]
}
}
Solved! Go to Solution.
- Labels:
-
Architect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 01:12 PM
Hello @Community Alums
Please refer below code -
// Base URL
var baseUrl = "";
// Step 1: Get Auth Token
var r = new sn_ws.RESTMessageV2('Test Integration', 'get token');
var TOKEN_SYS_PROP_NAME = '';
var authBodyContent = 'dXNlcm5hbWU9YWtob3Nobm9vZEBhY29yaW8uY29tJnBhc3N3b3JkPTEyMzQ=';
r.setStringParameterNoEscape('url', baseUrl);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
if (httpStatus !== 200) {
gs.error("Failed to fetch token. HTTP Status: " + httpStatus);
return;
}
TOKEN_SYS_PROP_NAME = "AR-JWT " + responseBody;
gs.log("Auth Token: " + TOKEN_SYS_PROP_NAME);
// Step 2: Fetch Incidents
var rm = new sn_ws.RESTMessageV2('Test Integration', 'get test incidents');
rm.setStringParameterNoEscape('authToken', TOKEN_SYS_PROP_NAME);
rm.setStringParameterNoEscape('url', baseUrl);
var response1 = rm.execute();
var responseBody1 = response1.getBody();
var parsedResponse = JSON.parse(responseBody1);
var httpStatus1 = response1.getStatusCode();
if (httpStatus1 !== 200) {
gs.error("Failed to fetch incidents. HTTP Status: " + httpStatus1);
return;
}
// Step 3: Process Incident Records
function processRecords(entries) {
for (var i = 0; i < entries.length; i++) {
var values = entries[i].values;
var gr = new GlideRecord('sn_customerservice_case'); // Replace with target table
gr.initialize();
gr.setValue('u_ticket_type', 'Incident');
gr.setValue('u_status', values["Status"] || "");
gr.setValue('u_priority', values["Priority"] || "");
gr.setValue('u_assigned_group', values["Assignment Group"] || "");
gr.setValue('u_impact', values["Impact"] || "");
gr.setValue('u_urgency', values["Urgency"] || "");
gr.setValue('u_incident_number', values["Incident Number"] || "");
gr.setValue('short_description', values["Description"] || "");
gr.insert();
gs.print("Inserted Record: " + values["Incident Number"]);
}
}
if (parsedResponse.entries && parsedResponse.entries.length > 0) {
processRecords(parsedResponse.entries);
}
// Step 4: Handle Pagination
if (parsedResponse._links && parsedResponse._links.next) {
var nextPageUrl = JSON.stringify(parsedResponse._links.next);
gs.print("Fetching next page: " + nextPageUrl);
}
gs.print("Process completed.");
You can add more fields if you want in the process of modification , I could do this much.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 12:31 PM
Hello @Community Alums
It's because it's an object - it could be a json object.
gs.print(JSON.stringify(parsedResponse._links));
Please try above, you need to confirm with the team what this link_next actually contains. I am assuming it to be a json object.
I guess I have answered your original query. Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 12:49 PM
Hello Shivalika,
That is next page URL only
Now, I am getting next page URL with below code:
So, I just need to pass the 'url' value to function now and it will iterate or anything else should be added to loop through each page?
if (parsedResponse._links) {
fetchRecords(JSON.stringify(parsedResponse._links.next));
}
Could you please add above code in the last entire code you have provided
Thanks,
Tejas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 12:51 PM
Hello @Community Alums
So it was a json object only - assumption correct.
Yes that's how it should work.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 12:56 PM
Yes, thank you
Probably last request!!
Shivalika,
could you please re-arrange the code once, below is my code so far
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 12:57 PM
Shivalika,
One request, could you please re-arrange the code once, below is my code so far
