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

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.


Thank you Justin.   It worked great!


That works beautifully!

SanjivMeher
Kilo Patron
Kilo Patron

Hi Carl,



Add a before insert/update business rule on Table "u_mobiles devices"



if (current.u_imei_string!='')


{


        current.name = current.u_imei_string;


}



Please mark this response as correct or helpful if it assisted you with your question.