How to get value from a reference field and copy it to the another reference field

naveenmyana
Giga Expert

Hi All,

I have a catalog item and have two reference fields, I have to get value from one reference field and copy that value to another reference field. I have tried the below script but it;s not working for me, Please suggest me the correct way here.

I have used Onload client script here...

function onLoad() {

var manager = g_form.getValue('Requesters_Manager');

alert(manager);

g_form.setValue('Resource_Manager',manager);

}

12 REPLIES 12

Great ! write on change on Requesters_Manager field.



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (isLoading || newValue === '') {


          return;


    }


g_form.setValue("Resource_Manager",newValue);


alert("You did it !!!");


    //Type appropriate comment here, and begin script below


}



Let me know if this was helpful


Hello Divya,



Thank you so much for your help Its working now...



But just small issue here, Here the requester manager value is autopopulated when the page loads and I have set a default value for that to get his manager value like this...


javascript:new getUserValues().getManager();



So when the page loads we can set the requesters manager as it is autopopulated, But here it won't set the resource manager as we have used onchane script here.



Is there any way can we fix this...


Aakash Shah4
Tera Guru

Hi,



You cannot copy a value into a reference field you need to copy a sys_id in a reference field


Hi AAkash,



I Have tried the below script and is returning the sys id...



script.PNG


divya mishra
Tera Guru

Well in that case a On load script will be useful. Keep in mind the order it executes.


condition should be if(g_form.getValue(fieldname) ! = '')


do the same code for populating the value.



Let me know if this was helpful