- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2016 04:45 AM
Thanks Manik that works.
Just one last tweak: how can I remove the space before the contextID?
I am getting this: ' 7a7307fa-07e7-ed7b-e736-99bfcf182f3f' insteade of '7a7307fa-07e7-ed7b-e736-99bfcf182f3f'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2016 04:50 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
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