Help with Client Script / Script Includes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 11:43 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 12:26 PM
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 '
});
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);
}
}
Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.
Regards,
Siddhesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 12:46 PM - edited 01-24-2024 12:50 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 04:04 AM
I found a correct solution using an onChange Client Script + GlideAjax using getXML.