Update a record via workflow script

dianemiro
Kilo Sage

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');
}
1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

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

-Anurag

View solution in original post

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

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

-Anurag

Hi Diane,

Just checking in to see if this worked or not?

-Anurag

-Anurag

Thanks Anurag. It works now!

Diane

Mike Patel
Tera Sage

You can do something like

var gr = new GlideRecord('cmn_location');
if(gr.get(current.variables.yourvariable)){
	gr.u_active = 'false';
	gr.update();
}