Script to copy the value of a field to another field in the same table

carlh
Kilo Guru

Hi All,

I am doing some clean up and need help.   I extended the CMDB_CI table and added a class called "Mobile Devices" for our phones and tablets but I didn't use the "NAME" field and now I can't see them from the reference field on my incident form.

find_real_file.png

Could someone share a script that will do the following?:

Table "u_mobiles devices"

If "u_imei_string" is not empty, copy the value in to the "name" field.

I plan to put a business rule in place to copy this in the future or I can just add the name field to the form.

Please let me know thoughts and if you are willing to share a script.

Thank you

Carl

1 ACCEPTED SOLUTION

Justin Abbott
Giga Guru

var gr = new GlideRecord('u_mobiles_devices');


gr.query();


while (gr.next()) {


  var x = gr.getValue('u_imei_string');


  if (x) {


          gr.setValue('name', x);


          gr.update();


  }


}



You could run that as a background script.


View solution in original post

5 REPLIES 5

thank you Sanjiv,   This was my plan to fix moving forward but had to get the clean up script first.   Appreciate your help!