auto populate a field based on a lookup select variable

Cupcake
Mega Guru

I have a catalog item that uses a table (which includes two fields: Name and Cost).

find_real_file.png

In the catalog item form - the name fields is a "Lookup select box type", and the cost field is a single line text

I want to auto populate the value of the cost based on the name selected from the lookup select box.

My script is not working - this is what i have. NOTE: The script will work perfectly if I change the name field to a reference field - but the issue with that is the existing tickets will loose the value selected.

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

      if (newValue == '') {

              g_form.setValue("sw_cost", "");

                                             

              return;

      }

     

      var u_sw_apps = g_form.getReference('app_select',CallBack);

}

function CallBack(u_sw_apps) {

      g_form.setValue("sw_cost", u_sw_apps.u_cost);

     

}

Any assistance is most appreciative.

Thank you,

Karen

24 REPLIES 24

sachin_namjoshi
Kilo Patron
Kilo Patron

You can change to reference field and then run one time fix script to update values.



Regards,


Sachin


Hi Sachin,


        Can you explain further about the one time fix script to update the values. Is this a script already within the system or something that I have to write?



Thanks,


Karen


Shishir Srivast
Mega Sage

Hi Karen,



I think the reason it works in case of reference field because as a reference field type gives the sys_id of the value and that helps to do gliderecord using getReference() function to get the record based upon the sys_id but in case of select Lookup select box type field it would be pointing to specific field name (selected in Lookup value field) and that i believe that will not help you get the sys_id of the record which you are trying to get using getReference() function.




find_real_file.png



In that case you need to try with GlideAjax to fetch the cost value based upon the value in name field.


Capture.PNG



Sorry, wasn't able to paste the code, looks like some issue, may be with my community account. try above sample type of code and see if this helps.