- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2021 04:02 AM
My requirement is to update multiple fields on incident table through rest scripted API and the situation is any field can be updated during PUT call which means It is not necessary that all the fields mentioned inside update function will be updated at once. it is not working well if I do it through Scripted API as my glide records are pushing Blank data to the incident. Here is my code snippet, Can you suggest what is the best way to get this worked or I need to update it through import set?
for example if Group is not updated only priority is updated, How can I control this so that only modified fields gets updated not all.
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var data = JSON.parse(request.body.dataString);
var group = data.assignment_group;
var impact = data.temp1;
var urgency = data.temp2;
var notes = data.work_notes;
var vendor_tkt = data.vendor_tkt;
//Set Assignement group based on Group name
if (group != "") {
var gp = new GlideRecord('sys_user_group');
gp.addQuery('u_legacy_group_name', group);
gp.query();
if (gp.next())
var gpid = gp.sys_id;
}
//set impact and Urgency
if(impact!="" && urgency!=""){
var imp, urg;
if (impact == "1-Extensive/Widespread" || impact == "2-Significant/Large")
imp = 1;
else if (impact == "3-Moderate/Limited")
imp = 2;
else if (impact == "4-Minor/Localized")
imp = 3;
if (urgency == "1-Critical" || urgency == "2-High")
urg = 1;
else if (urgency == "3-Medium")
urg = 2;
else if (urgency == "4-Low")
urg = 3;
}
var gr = new GlideRecord('incident');
gr.addQuery('third_party_reference', vendor_tkt);
gr.query();
if (gr.next())
gr.urgency = urg;
gr.impact = imp;
gr.assignment_group = gpid;
gr.work_notes = notes;
gr.update();
response.setStatus(200);
})(request, response);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2021 07:59 AM
Hi,
you can do this to check for emptiness and undefined
if(impact != '' && impact != undefined){
}
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
04-26-2021 08:55 PM
Glad to help.
Please remember to mark response helpful as well
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2025 02:58 AM
What will be the sys_update_by field ? whose name will it be in Activities?