How to write fix script to change the Name of field based on other field.

Shraddha Desai1
Tera Contributor

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?

find_real_file.png

 

 

Thanks & Regards 

Shraddha Desai

2 REPLIES 2

Jaspal Singh
Mega Patron
Mega Patron

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

Chetan Mahajan
Kilo Sage
Kilo Sage

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