Add option script not working

abirakundu23
Mega Sage

Hi All,

Based on the condition option will be visible to the select box, wrote onload catalog client script & script include. ut its not working properly.

Script Include:

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

checkemp: function(){
var SubjectPerson = this.getParameter('SubPerson');

var userRec = new GlideRecord('sys_user');
userRec.get(SubjectPerson);
var userALPSID = userRec.user_name;

var hrRec = new GlideRecord('sn_hr_core_profile');
hrRec.addQuery('employee_number',userALPSID);
hrRec.addEncodedQuery('u_contry=IN^user.u_consent_status=accepted^user.u_employee_type=INTERNAL^NQu_countryISEMPTY^user.u_consent_status=accepted^user.u_employee_type=INTERNAL^user.location.country=IN');
hrRec.query();

while(hrRec.next()){

return 'Yes';


}

},

type: 'CountrySubjectPerson'
});

 

onload catalog client script:

function onLoad() {



//Type appropriate comment here, and begin script below
//g_form.addInfoMessage(subject_person);
var emp = g_form.getValue('subject_person');
var empcheck = new GlideAjax('sn_hr_core.CountrySubjectPerson');
empcheck.addParam('sysparm_name', 'checkemp');
empcheck.addParam('SubPerson',emp);
empcheck.getXML(getCountryValue);
alert('Inside elseif');
}

function getCountryValue(response) {
var EmpCountry = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage(EmpCountry);
if(EmpCountry == 'Yes')
{
g_form.addInfoMessage('inside emp country');
g_form.clearOptions('please_select');
g_form.addOption('please_select','',"-- None --");

g_form.addOption('please_select_the_type_of_absence','Maternity,'Maternity');

}
}

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@abirakundu23 Please update your script include as follows.

 

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

checkemp: function(){
var SubjectPerson = this.getParameter('SubPerson');

var userRec = new GlideRecord('sys_user');
userRec.get(SubjectPerson);
var userALPSID = userRec.user_name;

var hrRec = new GlideRecord('sn_hr_core_profile');
hrRec.addQuery('employee_number',userALPSID);
hrRec.addEncodedQuery('u_contractual_country=Canada^user.u_consent_status=accepted^user.u_employee_type=INTERNAL^NQu_contractual_countryISEMPTY^user.u_consent_status=accepted^user.u_employee_type=INTERNAL^user.location.country=Canada');
hrRec.query();

if(hrRec.next()){

return 'Yes';


}

},


type: 'CountrySubjectPerson'
});

 

 

 

View solution in original post

4 REPLIES 4

_Gaurav
Kilo Sage

Hi @abirakundu23 
In your server script instead of WHILE replace it with IF.
Secondly, are you getting "g_form.addInfoMessage(EmpCountry);" as Yes ?
Also in your onLoad CS the variable name is different, please check.

Sandeep Rajput
Tera Patron
Tera Patron

@abirakundu23 Please update your script include as follows.

 

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

checkemp: function(){
var SubjectPerson = this.getParameter('SubPerson');

var userRec = new GlideRecord('sys_user');
userRec.get(SubjectPerson);
var userALPSID = userRec.user_name;

var hrRec = new GlideRecord('sn_hr_core_profile');
hrRec.addQuery('employee_number',userALPSID);
hrRec.addEncodedQuery('u_contractual_country=Canada^user.u_consent_status=accepted^user.u_employee_type=INTERNAL^NQu_contractual_countryISEMPTY^user.u_consent_status=accepted^user.u_employee_type=INTERNAL^user.location.country=Canada');
hrRec.query();

if(hrRec.next()){

return 'Yes';


}

},


type: 'CountrySubjectPerson'
});

 

 

 

abirakundu23
Mega Sage

hi @Sandeep Rajput,

I checked it seems working.

 

hi @_Gaurav ,

Yes info message display & changed to if. still its not working.

 

@abirakundu23 Can you check the scope of the SI?