Conflict Client scripts

ar1
Kilo Sage

Hi All,

Can anyone please help us on the below issue.

We developed one catalog item with few variables and variable sets.

and wrote two catalog client scripts, In that one client script in variable set. Both are working fine but some times the conflict is happening , as per the requirement 1st Catalog client script will run first, then based the conditions either the variable set client script will excute or not.

Both the scripts are running on same variables.

we changed the order but no luck, 

can anyone please help us to fix the issue.

Many thanks for the support.

 

1. Catalog Client script:

function onChange(control, oldValue, newValue, isLoading) {
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', 'checkRecordPresent');
ga.addParam('sysparm_userID',g_form.getValue('location'));
ga.getXMLAnswer(function(answer){
//alert(answer);
if(answer == 'show'){
g_form.setDisplay('bensl_id_detail',true);
g_form.setDisplay('bensl_id',true);
g_form.setDisplay('user_bensl_id',true);
g_form.setDisplay('structural_unit',true);
}

else{
g_form.clearValue('bensl_id');
g_form.setDisplay('bensl_id_detail',false);
g_form.setVisible('bensl_id_detail',false);
g_form.setDisplay('bensl_id',false);
g_form.setVisible('bensl_id',false);
g_form.setDisplay('user_bensl_id',false);
g_form.setVisible('user_bensl_id',false);
g_form.setDisplay('structural_unit',false);
g_form.setVisible('structural_unit',false);
}
});
}

 

Script include:

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

checkRecordPresent: function(){
var id = this.getParameter('sysparm_userID');
var gr = new GlideRecord('cmn_location');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
if(gr.u_location_type == 'XYZ' && gr.u_region == 'ABC')
return 'show';
else
return 'hide';
}
},

type: 'checkRecords'
});

 

2. Client script in variable set:

function onLoad() {
{
g_form.setReadOnly('bensl_id','true');
var usr = g_form.getValue('caller_id');
var usrajax = new GlideAjax('getbenslid');
usrajax.addParam('sysparm_name','getbensl');
usrajax.addParam('sysparm_usr',usr);
usrajax.getXML(callBackFunction);
//}
}

function callBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");

if(answer == '0'){
g_form.setDisplay('user_bensl_id',false);
g_form.setValue('bensl_id','No');

}
else if(answer > '0')
{
var benid = g_form.getValue('caller_id');

g_form.setValue('user_bensl_id',benid);
g_form.setValue('bensl_id','Yes');
g_form.setDisplay('user_bensl_id',true);
}}}

Script include:

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

getbensl: function(){
var usrdtls;
var usr = this.getParameter('sysparm_usr');
var usrrecrd = new GlideRecord('u_useracnt');
usrrecrd.addQuery('u_user_sysid',usr);
usrrecrd.addQuery('u_accdn','net');
usrrecrd.addQuery('u_accsta','Active').addOrCondition('u_accsta','Disabled');
usrrecrd.query();
var idcount = usrrecrd.getRowCount();
return idcount;

},

type: 'getbenslid'

});

 

 

Many thanks.

1 ACCEPTED SOLUTION

ar1
Kilo Sage

Thanks for the response.

i'm so stupid, In the UI policy the above mentioned variables are set as mandatory.

so that's the reason the above scripts working fine sometimes and sometimes don't.

After making the UI policy inactive, both the scripts working fine as per the requirement.

 

Many thanks for the support....

View solution in original post

3 REPLIES 3

Allen Andreas
Administrator
Administrator

Hello,

Because you removed the isLoading line from your onChange client script, both will run onLoad.

If you wish to use one for onLoad and then another for onChange, then you'd want to add this line back to your onChange client script, at the top (below the function starting line):

if (isLoading || newValue === '') {
      return;
   }

Otherwise, you didn't specify what the conflict is and it would help us...help you...if you gave more information. Ideally, we wouldn't have to read every line of what you've posted. Speaking of that...please use the appropriate forum feature when pasting script by using the: "Insert/Edit code sample" feature:

find_real_file.png

This keeps your code organized and easier to read.

Outside of what I've mentioned above, if there are other conflicts going on, you'll need to build appropriate if statements to prevent them from running over each other.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Maik Skoddow
Tera Patron
Tera Patron

Hi

both scripts perform asynchronous calls to the respective Script Includes. That way, you have no chance to force an execution order.

Kind regards
Maik

ar1
Kilo Sage

Thanks for the response.

i'm so stupid, In the UI policy the above mentioned variables are set as mandatory.

so that's the reason the above scripts working fine sometimes and sometimes don't.

After making the UI policy inactive, both the scripts working fine as per the requirement.

 

Many thanks for the support....