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

not sure, would take sachin.namjoshi help, made some more corrections in the script, can we try one more time and see if this helps, please have the catalog client script.



Script Include:


var getCostValue = Class.create();


getCostValue.prototype = Object.extendsObject (AbstractAjaxProcessor, {


getDetails: function() {


var newRecord = new GlideRecord ('u_sw_apps');


newRecord.addQuery('name', this.getParameter('sysparm_app_select'));


if(newRecord.next())


return newRecord.getValue('u_cost');


},


type: 'getCostValue'


});


No it didn't work.


Sorry when you say please have the catalog client script - what do you mean have the catalog client script what (Turned on?)


Hi Karen,



I meant to use Catalog Client Script.


So you want me to put the script include inside of the catalog client script.



This is what my catalog client script looks like right now (see below) - where in this script do you want me to include your script included.



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);      


              //}


              var ga = new GlideAjax('CostValue');


              ga.addParam('sysparm_name','getDetails');


              ga.addParam('sysparm_app_select',g_form.getValue('app_select'));


              ga.getXML(function(response){


                      var answer = response.responseXML.documentElement.getAttribute('answer');


                      alert(answer);


              });


      }


}