GlideAjax returns null value

Lon Landry4
Mega Sage

I have an onSubmit catalog client script & script includes. I am trying to populate the State (install_status) with asset matching a catalog variable. I have checked like posts but the solutions have not worked for me.

 
Client script (isolate script is false)
 
function onSubmit() {
  // Get the sys_id of the first_asset_returning variable
  var firstAssetSysId = g_form.getValue('first_asset_returning');
 
  // Use GlideAjax to call the server-side script
  var ga = new GlideAjax('PopulateFirstState'); 
  ga.addParam('sysparm_name', 'getInstallStatus');
  ga.addParam('sysparm_first_asset_returning_sys_id', firstAssetSysId);
 
  // Callback function for success
  ga.getXML(function (response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
 
    // Set the value of the first_state variable with the received answer
    g_form.setValue('first_state', answer);
alert(answer);
 
  });
}

 

Script includes (client callable is true, Accessible from All application scopes)

 

var PopulateFirstState = Class.create();
PopulateFirstState.prototype = Object.extendsObject(AbstractAjaxProcessor, {
  getInstallStatus: function () {
    // Get the sys_id parameter from the client-side
    var firstAssetSysId = this.getParameter('sysparm_first_asset_returning_sys_id');
 
    // Query the alm_hardware table to get the install_status value
    var hardwareGr = new GlideRecord('alm_hardware');
    if (hardwareGr.getValue(firstAssetSysId)) {
      var InstallStatus = hardwareGr.getValue('install_status');
 
      return InstallStatus;
    }  
  } 
});
1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Lon Landry4 Please update your script include script as follows and you will start getting the data on the client side.

 

var PopulateFirstState = Class.create();
PopulateFirstState.prototype = Object.extendsObject(AbstractAjaxProcessor, {
  getInstallStatus: function () {
    // Get the sys_id parameter from the client-side
    var firstAssetSysId = this.getParameter('sysparm_first_asset_returning_sys_id');
 
    // Query the alm_hardware table to get the install_status value
    var hardwareGr = new GlideRecord('alm_hardware');
    if (hardwareGr.get(firstAssetSysId)) { //Used get instead of getValue();
      var InstallStatus = hardwareGr.getValue('install_status');
      return InstallStatus;
    }  
  } 
});

Hope this helps.

View solution in original post

5 REPLIES 5

Tai Vu
Kilo Patron
Kilo Patron

Hi @Lon Landry4 

There's a couple of things below you can give a try.

1. In your script include, you're using getValue while getting a record. So let's change this line below.

From

 

if (hardwareGr.getValue(firstAssetSysId))

 

To

 

if (hardwareGr.get(firstAssetSysId))

 

 

2. It should be an OnChange Client Script instead of OnSubmit for your case.

 

3. You may want to check the Auto-populate feature.

Auto-populate a variable based on a reference type variable (Utah)

 

Cheers,

Tai Vu