The CreatorCon Call for Content is officially open! Get started here.

Help with Client Script / Script Includes

Lon Landry4
Mega Sage

Howdy Community,

I am trying to Populate catalog variable called first_state by matching catalog variable first_asset_returning sys_id with related hardware record’s install_status value.

 

What am I doing wrong?

 

My client-callable Script Includes:

 

var HardwareUtilsState = Class.create();
HardwareUtilsState.prototype = {
initialize: function(){},

getInstallStatus: function(hardwareSysId){
var installStatus = '';
var hardwareRecord = new GlideRecord('alm_hardware');
if (hardwareRecord.get(hardwareSysId)){
installStatus = hardwareRecord.getValue('install_status');
}
return installStatus;
},
type: 'HardwareUtilsState'
};

 

My Client Script:

function onLoad() {

//Get the sys_id of the first_asset_returning variable
var firstAssetReturningSysId = g_form.getControl('first_asset_returning');

//Call the script include function to get the install_status value
var hardwareUtilsState = new HardwareUtilsState();
var installStatus = hardwareUtilsState.getInstallStatus(firstAssetReturningSysId);

//Set the variable of the first_state variable
g_form.setValue('first_state', installStatus);
}

3 REPLIES 3

Siddhesh Gawade
Mega Sage
Mega Sage

Hello @Lon Landry4 ,

 

both the client script and script include will not work as they are not in proper syntax. And the script in not creating correct class. I have made changes in your script so please use this script and let me know if this works for you.

 

Create a script as below:

 

var HardwareUtilsState = Class.create();
HardwareUtilsState.prototype = Object.extendsObject(AbstractAjaxProcessor, {


    getInstallStatus: function() {
        var hardwareRec = this.getParameter('sysparm_hardwareSysId');
        var installStatus = '';
        var hardwareRecord = new GlideRecord('alm_hardware');
        if (hardwareRecord.get(hardwareRec)) {			
            installStatus = hardwareRecord.getValue('install_status');
        }
        return installStatus;
    },

    type: 'HardwareUtilsState '
});

 

SiddheshGawade_0-1706127355703.png

 

Create a Onchnage client script on first_asset_returning variable:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var assetSysId = g_form.getValue('first_asset_returning');
    alert(assetSysId);
    var ga = new GlideAjax('HardwareUtilsState');
    ga.addParam('sysparm_name', 'getInstallStatus');
    ga.addParam('sysparm_hardwareSysId', assetSysId);
    ga.getXMLAnswer(processResponse);

    function processResponse(reposnse) {
        alert('response is ' + reposnse);
g_form.setValue('first_state', installStatus);
    }

}

 

SiddheshGawade_1-1706127782748.png

 

 

Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.


Regards,

Siddhesh

Hi Siddesh,

I tried this approach earlier (AbstractAjaxProcessor), but was not successful.

I tried the scripts above, the correct sys_is is alerted. (good)
The response is 1
No error message.

 

I tried type: 'HardwareUtilsState ' & type: 'HardwareUtilsState'  at end of Script Includes

Lon Landry4
Mega Sage

I found a correct solution using an onChange Client Script + GlideAjax using getXML.