Hello Experts, How to set location field on alm_hardware, based on assigned_to (user)-location.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 12:16 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 12:26 AM
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();
}
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 02:52 AM
What referes -- .tostring() and this line hardwareGr.setWorkflow(false);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 03:19 AM
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.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 12:41 AM
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