Scope AJAX Script Include and Catalog Client Script

Luis Roman1
Tera Contributor

I have the following Ajax Scripts (Include and Client) in a scope application. For some reason I am getting a browser error: There is a JavaScript error in your browser console. Can you please advise me how to addressed this problem. I am in a lost and not sure how to proceed forward.  Help appreciated.

find_real_file.png

Catalog client script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
if (newValue === 'true') {
    alert('onChangeTelecommuter_telecommuter =true= ' + newValue);
    g_form.clearValue('building');
    g_form.clearValue('column');
    g_form.clearValue('floor');
    g_form.clearValue('room_cube');
} else {
    alert('onChangeTelecommuter_telecommuter =False= ' + newValue);
        var sys_id_asset = g_form.getValue('asset');
        var ga = new GlideAjax('x_g_lme_ham_classi.getStandardFields'); //this is the script include
        ga.addParam("sysparm_name", "getFields"); //this is the function within the script include
        ga.addParam("sysparm_asset", sys_id_asset);
        ga.getXML(getResponse);
    }
}

    function getResponse(response) {
        var values = response.responseXML.documentElement.getAttribute('answer').toString().split('|');
        g_form.setValue('location', values[0]);
        g_form.setValue('building', values[1]);
        g_form.setValue('floor', values[2]);
        g_form.setValue('column', values[3]);
        g_form.setValue('room_cube', values[4]);
    }

Script Include:

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

getFields : function() {
var assetID = this.getParameter('sysparm_asset');
var standardFields = new GlideRecord('alm_asset');
standardFields.addQuery('sys_id',assetID);
 standardFields.query();
if(standardFields.next()) {
return standardFields.location.getDisplayValue()+ '|' +
standardFields.u_building.getDisplayValue()+'|' +
standardFields.u_floor.getDisplayValue()+ '|'+
standardFields.u_column.getDisplayValue()+ '|'+
standardFields.u_room_cube.getDisplayValue();
}
return '';
},
    type: 'getStandardFields'
});

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi @Luis Roman 

try to use getXMLAnswer() in client script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (newValue === 'true') {
        alert('onChangeTelecommuter_telecommuter =true= ' + newValue);
        g_form.clearValue('building');
        g_form.clearValue('column');
        g_form.clearValue('floor');
        g_form.clearValue('room_cube');
    } else {
        alert('onChangeTelecommuter_telecommuter =False= ' + newValue);
        var sys_id_asset = g_form.getValue('asset');
        var ga = new GlideAjax('x_g_lme_ham_classi.getStandardFields'); //this is the script include
        ga.addParam("sysparm_name", "getFields"); //this is the function within the script include
        ga.addParam("sysparm_asset", sys_id_asset);
        ga.getXMLAnswer(getResponse);
    }
}

function getResponse(response) {
    var values = response.toString().split('|');
    g_form.setValue('location', values[0]);
    g_form.setValue('building', values[1]);
    g_form.setValue('floor', values[2]);
    g_form.setValue('column', values[3]);
    g_form.setValue('room_cube', values[4]);
}

Update script include as this since you are in scope application

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

getFields : function() {
var assetID = this.getParameter('sysparm_asset');
var standardFields = new GlideRecord('alm_asset');
standardFields.addQuery('sys_id',assetID);
 standardFields.query();
if(standardFields.next()) {
return standardFields.location.getDisplayValue()+ '|' +
standardFields.u_building.getDisplayValue()+'|' +
standardFields.u_floor.getDisplayValue()+ '|'+
standardFields.u_column.getDisplayValue()+ '|'+
standardFields.u_room_cube.getDisplayValue();
}
return '';
},
    type: 'getStandardFields'
});

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Hi,

are you sure there is field u_building on alm_asset?

Are you sure the field types are same i.e. u_building and building; both location fileds

If field types are same then it should work fine

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader