How to write fix script to change the Name of field based on other field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 01:57 AM
Hello ,
On our record their are two field Name and Space type. So for Hotel desk space type we have several record. We want rename the name of each record having space type= Hotel desk. And name should be start from HD and number which already exist. eg. HD 6-097. so how I do from fix script?
Thanks & Regards
Shraddha Desai

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 02:03 AM
Try something as below
var tableis=new GlideRecord('table_name');//replace table_name
tableis.setLimit(2);//execute for 2 records only first for a check
tablis.query();
while(tableis.next())
{
tableis.u_final=tableis.u_name+' '+tableis.u_space_type.getDisplayValue();
tablelis.upate();
}
//Replace field & table name accordingly. Test it in background script once for few sample records

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 02:09 AM
Hi Shradhha,
you can below script to update all record whose space type is hotel desk and name start with HD and it will run on existing records only so no need to check numbers, just filter records on table copy query from breadcrumb and pest in encoded query check below code for ref.
var encodedQuery = 'space_type=Hotel_desk^nameSTARTSWITHhd'; // add query from filter query on table
var gr = new GlideRecord('table_name');
gr .addEncodedQuery(encodedQuery);
gr .query();
while(gr.next()){
gr.setValue('name','new_hotelName'); // set whatever value you want to set on existing records
gr.update();
}
Kindly mark correct and helpful if applicable