How to call multiple functions in OnChange catalog client script from script include

sinu2
Tera Expert

Hi All,

 

I have a requirement in my catalog item "user" is the reference field and "cost_center" is the single line text and "sample" is also single line text field .

1. if user.location =="abc" OR user.location== ''def" OR user.location =="ghi" the "cost_center" field should should visible else hidde.

2.if user.location.parent =="abc" OR  user.location.parent =="xyz" then "sample" filed should visible else hidden

3. if user.location !="abc" OR user.location !=''def" OR user.location !="ghi" the "cost_center" field should should visible else hidden.

for this i have written scrit include and catalog client script for one functon it is working great but whle i have written another function to check another condition it is not working.

Please find the below scripts and kindly suggest where is the issue.

@note : i have written client script to work for both onload and onchange

Script include@@@@@@@@@@@@@@@@@@@@@@@@@

 

var smart_phone_fields_visible = Class.create();
smart_phone_fields_visible.prototype = Object.extendsObject(AbstractAjaxProcessor, {
HardwareUserLocation: function(){

var retVal;
var user = this.getParameter('sysparm_user');
//var amerus1= this.getParameter('sysparm_location');
//var amerca1 = this.getParameter('sysparm_location_AmerCA');
var bsa1 = this.getParameter('sysparm_location_BSA');
var rhe1 = this.getParameter('sysparm_location_RHE');
var wol1 = this.getParameter('sysparm_location_WOL');


var detailsRec = new GlideRecord('sys_user');
detailsRec.get(user);
//var parentLoc = detailsRec.location.parent;
gs.info(detailsRec.location.getDisplayValue()+'----amerus1-----'+amerus1+'----'+user);
if(detailsRec.location.getDisplayValue()+'' == bsa1 || detailsRec.location.getDisplayValue()+'' == rhe1 || detailsRec.location.getDisplayValue()+'' == wol1)
{

return true;

}
else{

return false;
}

},

HardwareUserLocation2: function(){
var user = this.getParameter('sysparm_user');
var amerus1= this.getParameter('sysparm_location');
var amerca1 = this.getParameter('sysparm_location_AmerCA');


var detailsRec = new GlideRecord('sys_user');
detailsRec.get(user);
//var parentLoc = detailsRec.location.parent;
gs.info(detailsRec.location.getDisplayValue()+'----amerus1-----'+amerus1+'----'+user);
if(detailsRec.location.parent.getDisplayValue()+'' == amerus1 || detailsRec.location.parent.getDisplayValue()+'' == amerca1)
{

return true;

}
else{

return false;
}

},

type: 'smart_phone_fields_visible'
});

 

Catalog client script@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

 

function onChange(control, oldValue, newValue, isLoading) {

//alert('newValue'+newValue);
alert(g_form.getValue('user'));
if (newValue == ''){
var ga = new GlideAjax('smart_phone_fields_visible');//name of script include


ga.addParam('sysparm_name', 'HardwareUserLocation');//name of function on script include


ga.addParam('sysparm_user', g_form.getValue('user'));//name of field on form triggering call
ga.addParam('sysparm_location','AMER-US');
ga.addParam('sysparm_location_AmerCA','AMER-CA');
ga.addParam('sysparm_location_BSA','BSA');
ga.addParam('sysparm_location_RHE','RHE');
ga.addParam('sysparm_location_WOL','WOL');

ga.getXML(HardwareDetailsLookup1); // Always try to use asynchronous (getXML) calls rather than synchronous (getXMLWait)


//calling second function

var ga2 = new GlideAjax('smart_phone_fields_visible');//name of script include


ga2.addParam('sysparm_name', 'HardwareUserLocation2');//name of function on script include


ga2.addParam('sysparm_user', g_form.getValue('user'));//name of field on form triggering call
ga2.addParam('sysparm_location','AMER-US');
ga2.addParam('sysparm_location_AmerCA','AMER-CA');
ga2.getXML(HardwareDetailsLookup2);

return;
}

// Callback function to process the response returned from the server

 

 

var ga1 = new GlideAjax('smart_phone_fields_visible');//name of script include


ga1.addParam('sysparm_name', 'HardwareUserLocation');//name of function on script include


ga1.addParam('sysparm_user', g_form.getValue('user'));//name of field on form triggering call
ga1.addParam('sysparm_location','AMER-US');
ga1.addParam('sysparm_location_AmerCA','AMER-CA');
ga1.addParam('sysparm_location_BSA','BSA');
ga1.addParam('sysparm_location_RHE','RHE');
ga1.addParam('sysparm_location_WOL','WOL');

ga1.getXML(HardwareDetailsLookup1); // Always try to use asynchronous (getXML) calls rather than synchronous (getXMLWait)

//
var ga3 = new GlideAjax('smart_phone_fields_visible');//name of script include


ga3.addParam('sysparm_name', 'HardwareUserLocation2');//name of function on script include


ga3.addParam('sysparm_user', g_form.getValue('user'));//name of field on form triggering call
ga3.addParam('sysparm_location','AMER-US');
ga3.addParam('sysparm_location_AmerCA','AMER-CA');

ga3.getXML(HardwareDetailsLookup2);
}

// Callback function to process the response returned from the server

function HardwareDetailsLookup1(response) {

var answer = response.responseXML.documentElement.getAttribute("answer");
alert('answer'+answer);

if(answer == 'true'){
alert('inside active');
g_form.setVisible('kostenstelle',true);
g_form.setMandatory('kostenstelle',true);
g_form.setVisible('handynummer',true);
g_form.setVisible('handyvertrag',true);
g_form.setVisible('optionen_f_r_handyvertrag_business_flex_multisim',true);
g_form.setVisible('optionen_f_r_handyvertrag_business_flex_datenvolumen',true);
g_form.setVisible('optionen_f_r_handyvertrag_business_flex_hotspot',true);
g_form.setVisible('surfstick',true);
}
else{
alert('inside loop else');
g_form.setVisible('kostenstelle',false);
g_form.setMandatory('kostenstelle',false);
g_form.setVisible('handynummer',false);
g_form.setVisible('handyvertrag',false);
g_form.setVisible('optionen_f_r_handyvertrag_business_flex_multisim',false);
g_form.setVisible('optionen_f_r_handyvertrag_business_flex_datenvolumen',false);
g_form.setVisible('optionen_f_r_handyvertrag_business_flex_hotspot',false);
g_form.setVisible('surfstick',false);
}


}

// Always try to use asynchronous (getXML) calls rather than synchronous (getXMLWait)

//


function HardwareDetailsLookup2(response) {

var answer = response.responseXML.documentElement.getAttribute("answer");
alert('answer'+answer);

if(answer == 'true'){
alert('inside active');
g_form.setVisible('cost_center',true);
g_form.setMandatory('cost_center',true);

}
else{
alert('inside loop else');
g_form.setVisible('cost_center',false);
g_form.setMandatory('cost_center',false);
}


}

2 REPLIES 2

Brian Lancaster
Tera Sage

Are these fields on a table or are these service catalog variables?

Yes these are catalog variables.