Copy data from a string field to a reference field

Wayne Richmond
Tera Guru

We are currently populating a field on our User table from Okta called 'mobile_phone'. I need to copy this data to a reference field called 'u_affiliate'. I don't want the update to happen if the mobile_phone field is empty. I tried to do this as a Business Rule when the record is updated/inserted but couldn't get it to work. Does anyone know how I might achieve this? Alternatively I could schedule a script to run nightly instead of a BR but I don't know how to do that either. Any help is much appreciated.

1 ACCEPTED SOLUTION

Thanks Wayne for the update. Please create a before business rule with below script.


var gr = new GlideRecord('u_affiliates');


gr.addQuery('field column name', current.mobile_phone);


gr.query();


while(gr.next())


  {


  current.u_affiliates = gr.sys_id;


}



NOTE : Replace field column name in line 2 with the exact field column name and make sure all column names and table name are adjusted properly.


Please let me know if you are blocked.


View solution in original post

10 REPLIES 10

nitin_kumar
Mega Guru

Is there a field called mobile phone in the 'u_affiliates' table too? If yes



Business Rule


table : sys_user


when : before Insert/Update


Advanced : true


Filter condition : mobile_phone field is   not empty



var gr = new GlideRecord('u_affiliates');


gr.addQuery('mobile_phone', current.mobile_phone);


gr.query();


if(gr.next()){


        current.u_affiliate = gr.sys_id;


}