The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Hello Experts, How to set location field on alm_hardware, based on assigned_to (user)-location.

mastan babu ko1
Tera Contributor

how to create the fix script to set location field on alm_hardware, based on assigned_to (user)-location. We need to update that perticular location.

6 REPLIES 6

Anil Lande
Kilo Patron

Hi,

you can use below logic:

var hardwareGr = new GlideRecord('alm_hardware');
//add additional queries to get records for your requirement.
hardwareGr.query(); 
while(hardwareGr.next()){
hardwareGr.location = hardwareGr.assigned_to.location.toString();
hardwareGr.setWorkflow(false);
hardwareGr.update();
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

What referes -- .tostring()  and this line   hardwareGr.setWorkflow(false);

 

To string is just to change the type of data into string.

setWorkflow(false) is used to avoid running Business rules when bulk records are updated.

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Danish Bhairag2
Tera Sage
Tera Sage

Hi @mastan babu ko1 ,

 

U can try with the below logic

 

var gr = new GlideRecord('alm_hardware');
gr.addEncodedQuery('assigned_to!=NULL');
gr.query(); 
while(gr.next()){
gr.location = gr.assigned_to.location.toString();
gr.setWorkflow(false);
gr.update();
}

 

Thanks,

Danish