onChange Catalog Client script does not work in portal

Chris Dea1
Tera Contributor

Hi there,

 

I am working on a new catalog item that generates an incident.  I have a requirement to auto-populate some location-related catalog item variables such as "county_name" and "county_code" based on values from the user's (sys_user) location (display value fields from the user's location from cmn_location).  The following onChange script is working correctly only in catalog view (activates when user enters something for "username" variable). 

 

The script basically looks at the requested_by on the incident, does lookup on sys_user, then does lookup of user's location on cmn_location, does another lookup on cmn_location to get the values of "name" and "u_school_id" from the parent.

 

Again it works in catalog view but for some reason this will not work at all in the portal view.  I have changed the "UI Type" to "All" but that did not help, it still only works in catalog view (when I click "Try it").  Can anyone advise what I am doing wrong?  Please share any code/corrections to get this working in the portal.

 

 

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
       return;
    }
    //GlideRecord the company table and make sure the vendor has a primary contact with a valid email address
 
     var user = new GlideRecord('sys_user');
     user.addQuery('sys_id', g_form.getValue('requested_by'));
     user.query();
     
    if (user.next()) {
        if (user.location == '') {
            g_form.setValue('district_name', 'NODIST');
        } else {
            g_form.setValue('district_name', user.location);

			var grLoc = new GlideRecord('cmn_location');
			grLoc.get(user.location);

            g_form.setValue('district_number', grLoc.u_school_id);
            g_form.setValue('county_name', grLoc.parent);

            var grParentLoc = new GlideRecord('cmn_location');
            grParentLoc.get(grLoc.parent);
            if (grParentLoc == '') {
                g_form.setValue('county_name', 'NOCOUNTY');
            } else {
                g_form.setValue('county_name', grParentLoc.name);
                g_form.setValue('county_code', grParentLoc.u_school_id);
            }
        }	 	
     }
}

 

 

 

 

Thanks for any help!

 

-Chris