Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Catalog client script is not working in portal but working when I do a Try It in maintain items

Priyanka145
Tera Contributor

Hi All,

 

I have written a catalog client script to display asset information based on requested for field

It is working fine when I do a 'Try It' in catalog item , but not in service portal.

 

function onChange(control, oldValue, newValue, isLoading) {
      var rfor = g_form.getValue('requested_for');
    var grd = new GlideRecord('alm_hardware');
    grd.addQuery('assigned_to', rfor);
    grd.query();
    if (grd.next()) {
        var asset = grd.asset_tag;
    }
    g_form.setValue('device_information', asset);
}
 
This is an on change catalog client script written on requested for field.
Please guide
1 ACCEPTED SOLUTION

@Priyanka145 Try the below script to clear if the user doesn't have any asset attached in alm_hardware table.

 

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

    var rfor = g_form.getValue('requested_for');
    var grd = new GlideRecord('alm_hardware');
    grd.addQuery('assigned_to', rfor);
    grd.query(setAssetInfo);

    function setAssetInfo(grd) {
        if (grd.next()) {
            var asset = grd.asset_tag;
            g_form.setValue('device_information', asset);
        }else{
			g_form.setValue('device_information', "");
		}
    }

}

 

Can you please mark my answers helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh

View solution in original post

6 REPLIES 6

@Priyanka145 Try the below script to clear if the user doesn't have any asset attached in alm_hardware table.

 

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

    var rfor = g_form.getValue('requested_for');
    var grd = new GlideRecord('alm_hardware');
    grd.addQuery('assigned_to', rfor);
    grd.query(setAssetInfo);

    function setAssetInfo(grd) {
        if (grd.next()) {
            var asset = grd.asset_tag;
            g_form.setValue('device_information', asset);
        }else{
			g_form.setValue('device_information', "");
		}
    }

}

 

Can you please mark my answers helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh

@Priyanka145 Can you please also mark my answers helpful as it helped you 👍

Thanks,
Anvesh