- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2019 07:25 AM
Hi Everyone,
I am trying to create a workflow to automate the updating of locations via Service Catalog. I used Run Script in workflow using this script:
var loc = current.variables.loc_location_remove; //getting the reference variable on the catalog item referencing to location table.
var locGR = new GlideRecord('cmn_location');
locGR.addQuery('sys_id',loc);
if(locGR.next()) {
locGR.u_active = 'false';
locGR.company = '';
locGR.account = '';
locGR.update();
gs.log(loc);
gs.log('Location: '+loc+' marked as inactive');
}
else{
gs.log('Location: '+loc+' not marked as inactive');
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2019 07:27 AM
HI Diane,
You missed locGR.query();
So the whole thing becomes
var loc = current.variables.loc_location_remove; //getting the reference variable on the catalog item referencing to location table.
var locGR = new GlideRecord('cmn_location');
locGR.addQuery('sys_id',loc);
locGR.query();
if(locGR.next())
{
locGR.u_active = 'false';
locGR.company = '';
locGR.account = '';
locGR.update();
gs.log(loc);
gs.log('Location: '+loc+' marked as inactive');
}
else{
gs.log('Location: '+loc+' not marked as inactive');
}
Instead of addQuery and next you can also just use gr.get() also.
Please mark my answer correct/helpful if it helps you solve your issue.
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2019 07:27 AM
HI Diane,
You missed locGR.query();
So the whole thing becomes
var loc = current.variables.loc_location_remove; //getting the reference variable on the catalog item referencing to location table.
var locGR = new GlideRecord('cmn_location');
locGR.addQuery('sys_id',loc);
locGR.query();
if(locGR.next())
{
locGR.u_active = 'false';
locGR.company = '';
locGR.account = '';
locGR.update();
gs.log(loc);
gs.log('Location: '+loc+' marked as inactive');
}
else{
gs.log('Location: '+loc+' not marked as inactive');
}
Instead of addQuery and next you can also just use gr.get() also.
Please mark my answer correct/helpful if it helps you solve your issue.
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2019 01:31 AM
Hi Diane,
Just checking in to see if this worked or not?
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2019 07:50 AM
Thanks Anurag. It works now!
Diane

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2019 07:36 AM
You can do something like
var gr = new GlideRecord('cmn_location');
if(gr.get(current.variables.yourvariable)){
gr.u_active = 'false';
gr.update();
}