Cannot get value from a different field(variable) in catalog client script

Alex I
Tera Contributor

I have a Catalog Client Script that is using a reference field for it's selected Variable name. I have it set for it to use GlideAjax to receive the price of record from the reference. I have another variable called 'Quantity' that I want to use to retrieve the value for. However, using the getValue() method I cannot seem to retrieve the value at all. I've tried other methods such as:

g_form.getValue('quantity');
g_form.getIntValue('quantity');
g_form.getDisplayValue('quantity');
g_form.getDisplayBox('quantity');
g_form.getDisplayBox('quantity').value;
g_form.getDisplayBox('quantity').toString();

I've tried them with and without Number() and parseInt() but it does not work! How to fix this?

 

For reference, here's the full script currently:

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   if (newValue != undefined) {
    var mainObj = new GlideAjax('getDeviceInfo');
    mainObj.addParam('sysparm_name', 'getPrice');
    mainObj.addParam('sysparm_name_id', newValue);
    mainObj.getXML(priceInfo);
   }

}

function priceInfo(result) {
    var price = result.responseXML.documentElement.getAttribute('answer');
    var product = Number(g_form.getValue('quantity'));
    g_form.setValue('total_amount', product);
}
 
Never mind, I think I've figured it out. The script is an onChange script that triggers when the reference field is changed. Since this happens before the Quantity field is filled in, the script never has the opportunity to fetch the Quantity value unless I enter it before selecting the reference.
0 REPLIES 0