- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2016 03:30 AM
I am trying to get a value from a description field then querying the location table against the value, but it doesn't seem to work. Have I missed anything in the script below?
(function executeRule(current, previous /*null when async*/) {
//gs.log("ContextID: "+contextID, "AV Created Incident");
gs.log("AV Location Script");
var contextID = "";
var AVdescription = current.description;
if(AVdescription.indexOf("Context:") > -1){
contextID = AVdescription.match("Context:(.*?)&");
contextID = contextID[1];
gs.log(contextID);
//var search_phrase = "****************************************************";
//var search_description = current.description.substring(0, current.description.indexOf(search_phrase));
//s.setStringParameter('description', search_description);
var locationRecord = new GlideRecord('cmn_location');
locationRecord.addQuery('u_context_id', contextID);
locationRecord.query();
if (locationRecord.next()) {
current.location = locationRecord.sys_id;
current.company = locationRecord.company;
gs.log(locationRecord);
} else {
sComments = '<br>WARNING - THIS ALERT DOES NOT HAVE A CORRESPONDING SITE IN SERVICENOW - PLEASE INFORM THE LOCAL SERVICENOW ADMIN<br><br>'+ sComments;
}
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2016 04:51 AM
Never mind got it working. Thank you very much for your help.
Here is the final script:
(function executeRule(current, previous /*null when async*/) {
gs.log("AV Location Script - Start");
var desc = current.description;
var pos = desc.search('Context:');
var contextID = desc.substring(pos+8);
contextID = contextID.trim();
var locationRec = new GlideRecord('cmn_location');
locationRec.addQuery('u_context_id', contextID);
locationRec.query();
if (locationRec.next()) {
current.location = locationRec.sys_id;
current.company = locationRec.company.sys_id;
}
else {
current.work_notes = '<br>WARNING - THIS ALERT DOES NOT HAVE A CORRESPONDING SITE IN SERVICENOW - PLEASE INFORM THE LOCAL SERVICENOW ADMIN.';
}
//gs.log("AV Location Script - End");
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2016 04:11 AM
Hi Abdul,
You can try using this code and it would return Context ID.
var pos = desc.search('Context:');
var res = desc.substring(pos+8);
gs.log(res);
Thanks,
Manik
PS - Please mark correct, like or helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2016 06:03 AM
Yes Abdul, you can use trim to remove spaces.
Thanks,
Manik
PS - Please mark correct, like or helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2016 05:22 AM
You can use trim function for removing extra spaces...
http://wiki.servicenow.com/index.php?title=Eliminate_Leading_and_Trailing_Spaces_in_Fields#gsc.tab=0
Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.
Thanks,
Deepa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2017 08:19 AM
Hi Deepa,
I am actually trying to use this right now... but i need to manipulate this script a little bit. Any idea how best to make this a catalog client script?
Any help would be greatly appreciated!
Thanks!