- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2022 02:46 PM
The sample payload that came to us contained the user details in the work notes. I Mentioned Payload Work Notes Details In Incident Work Notes In Scripted Rest API. But for me the incident form is reflected as work notes [object Object].
Please help me
sample payload:
{
inc.initialize();
inc.work_notes = WorkNotes;
incident_sys_id = incSubmission;
var incNumber = new GlideRecord('incident');
incNumber.addQuery('sys_id', incSubmission);
incNumber.query();
if (incNumber.next()) {
incident_number = incNumber.number;
}
Solved! Go to Solution.
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2022 12:00 AM
Hi UDV,
Is the question about inserting an incident and a worknote?
If so, following Scripted REST API will insert a record. Incident "Number" field is automatically generated and field "caller id" is mandatory so I've change the script accordingly.
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
try {
var requestData = request.body.dataString;
var json = JSON.parse(requestData);
var inCallerId = json.caller_id;
var inShortDescription = json.short_description;
var workNotes = json.work_notes;
var wnName = workNotes.Name;
var wnEmail = workNotes.Email;
var wnManager = workNotes.Manager;
var wnPhone = workNotes.Phone;
var grIncident = new GlideRecord('incident');
grIncident.initialize();
//grIncident.number = inNumber;
grIncident.caller_id = inCallerId;
grIncident.short_description = inShortDescription;
var incidentSysId = grIncident.insert();
var grJournal = new GlideRecord('sys_journal_field');
grJournal.initialize();
grJournal.name = 'incident';
grJournal.element = 'comments';
grJournal.element_id = incidentSysId;
grJournal.value = 'Name:' + wnName + '\nEmail:' + wnEmail + '\nManager:' + wnManager + '\nPhone:' + wnPhone;
grJournal.insert();
return {
'message': incidentSysId
};
} catch (e) {
return {
'error': e.message
};
}
})(request, response);
Tested with following curl command.
curl -u <user name>:<password> -X POST -d '{"caller_id":"<sys_user sys_id>","correlation_display":"","number":"INCXXXXXX","priority":"P2","state":"New","contact_type":"Self-service","short_description":"Test API Incident insert","description":"Test","work_notes":{"Name":" Demo","Email":"demo@demo.com","Manager":"demo","Phone":"9874564"},"comments":"Test","close_notes":"","close_code":"","assignment_group":"Test"}' https://<instance name>.service-now.com/api/<workspace name>/worknotes -H "Content-Type:application/json"
Result
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2022 10:41 PM
Hi,
data for work notes is an object so you need to parse it to go inside and fetch the data
So what do you wish to fetch from this?
WorkNotes = reqData.work_notes;
var name = reqData.work_notes.Name;
var email = reqData.work_notes.Email;
\\ create incident
var inc = new GlideRecord('incident');
inc.initialize();
inc.work_notes = WorkNotes;
var incSubmission = inc.insert();
incident_sys_id = incSubmission;
var incNumber = new GlideRecord('incident');
incNumber.addQuery('sys_id', incSubmission);
incNumber.query();
if (incNumber.next()) {
incident_number = incNumber.number;
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2022 09:33 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2022 12:00 AM
Hi UDV,
Is the question about inserting an incident and a worknote?
If so, following Scripted REST API will insert a record. Incident "Number" field is automatically generated and field "caller id" is mandatory so I've change the script accordingly.
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
try {
var requestData = request.body.dataString;
var json = JSON.parse(requestData);
var inCallerId = json.caller_id;
var inShortDescription = json.short_description;
var workNotes = json.work_notes;
var wnName = workNotes.Name;
var wnEmail = workNotes.Email;
var wnManager = workNotes.Manager;
var wnPhone = workNotes.Phone;
var grIncident = new GlideRecord('incident');
grIncident.initialize();
//grIncident.number = inNumber;
grIncident.caller_id = inCallerId;
grIncident.short_description = inShortDescription;
var incidentSysId = grIncident.insert();
var grJournal = new GlideRecord('sys_journal_field');
grJournal.initialize();
grJournal.name = 'incident';
grJournal.element = 'comments';
grJournal.element_id = incidentSysId;
grJournal.value = 'Name:' + wnName + '\nEmail:' + wnEmail + '\nManager:' + wnManager + '\nPhone:' + wnPhone;
grJournal.insert();
return {
'message': incidentSysId
};
} catch (e) {
return {
'error': e.message
};
}
})(request, response);
Tested with following curl command.
curl -u <user name>:<password> -X POST -d '{"caller_id":"<sys_user sys_id>","correlation_display":"","number":"INCXXXXXX","priority":"P2","state":"New","contact_type":"Self-service","short_description":"Test API Incident insert","description":"Test","work_notes":{"Name":" Demo","Email":"demo@demo.com","Manager":"demo","Phone":"9874564"},"comments":"Test","close_notes":"","close_code":"","assignment_group":"Test"}' https://<instance name>.service-now.com/api/<workspace name>/worknotes -H "Content-Type:application/json"
Result