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

Still didn't work.



I also started out doing a catalog client script. Is there a way that we can include the script include inside of this and if so - how would you do that. Not sure of where to include the script include.



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


      if (isLoading) {


              return;


      }else if(newValue == ''){


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


      }else{


              var sw_app = new GlideRecord("u_sw_apps");


              var sel_app = sw_app.get(newValue);


              if(sel_app == true){


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


              }


      }


}



Thanks,


Karen


it's not recommended to have GlideRecord query done in client script. I would say have the catalog client script + script include.


Let me know if it's your personal dev instance, i can have a quick look.


No not my personal Dev instance. Sorry.


It is the company instance.



Not sure why the client script + script include is not working



It must be a small piece that is missing.


Hope you have catalog client script instead of client script.


The only way the catalog client script worked was to change the variable type to a Reference field and it worked perfectly.


The issue with doing that is if there are any requests that was submitted prior to this change will loose all the values.



Another developer in this the thread recommended doing a script to Fix the values, but he never provided the assistance. I asked him about the script but never responded. If you look earlier in the conversation - maybe you can provide some insight on the script to fix the values when you change a variable type from one thing to another.



Thanks again.


Karen