Script Include returning null

Raviteja K
Tera Expert

Hello Everyone

I have following client script

var userDet = g_form.getReference('openedfor');

var ga = new GlideAjax('HRManagerApprovalCheck');

ga.addParam('sysparm_name','ApprovalCheck');

ga.addParam('sysparam_userDet','userDet');

ga.getXML(GetCountryDetails);

function GetCountryDetails(response) {

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

    alert(answer);

}

and following script include

getUserData: function()

{

var userDet = this.getParameter('sysparam_userDet');

var det = userDet.country;

var countryapp='';

var user = new GlideRecord('u_hr_country_and_approval_lookup');

user.addQuery('u_country',det);

user.query();

while (user.next()) {

countryapp=user.u_line_manager_approval_required;

}

return countryapp;

},

This should Yes, but returning null

Need to do any changes to the client script or script include.

Thanks in advance.

1 ACCEPTED SOLUTION

PriyaRanji
Tera Guru

Hi Ravi,



Try to make some changes as below and run it from your end. Hope it works!



I have added the logs & alerts to check the values that we receive and to find out where it exactly goes wrong in case it fails.



I have commented some code as it is not required, and highlighted the newly added code for your reference.



Client Script:



//var userDet = g_form.getReference('openedfor');


var country = g_form.getReference('openedfor').country;/*it will returns you the country */


alert('The country is'+country);


var ga = new GlideAjax('HRManagerApprovalCheck');


ga.addParam('sysparm_name','ApprovalCheck');


//ga.addParam('sysparm_userDet',userDet);


ga.addParam('sysparm_country',country);


ga.getXML(GetCountryDetails);



function GetCountryDetails(response) {


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


    alert(answer);


}



Script include Name : HRManagerApprovalCheck



ApprovalCheck : function()


{


//var userDet = this.getParameter('sysparm_userDet');



var country = this.getParameter('sysparm_country');


gs.log('country is'+country);



//var det = userDet.country;



var countryapp='';


var user = new GlideRecord('u_hr_country_and_approval_lookup');


user.addQuery('u_country',country);


user.query();


if(user.next()) {


gs.log('I m in');


countryapp=user.u_line_manager_approval_required;


gs.log('countryapp:'+countryapp);


}


return countryapp;


},



Please let me know in case of any concerns. Please mark it as correct/helpful based on the impact of the response you get!



Thanks,


Priyanka R


View solution in original post

16 REPLIES 16

samiul1
Tera Expert

Few questions:



1) var userDet = g_form.getReference('openedfor') ==> 'openedfor' is this field referenced field?



2)


var ga = new GlideAjax('HRManagerApprovalCheck');


ga.addParam('sysparm_name','ApprovalCheck');


ga.addParam('sysparam_userDet','userDet');



is your Script Include name correct as "HRManagerApprovalCheck" ?


is the function name within your Script Include as "ApprovalCheck" ? cause, the function you mentioned here is : "getUserData : function()".



3) what's the point using g_form.getReference() and ScriptInclude/Glideajax at the same time?



Confirm the above then will advise further.


Hi Samiul,



1) Yes it is a reference field.



2) HRManagerApprovalCheck is the script include name I am using


changed script to ApprovalCheck: function();



3) Need to check value whether that country is having approval process or not based on requestor's country. If requestor's country is not having approval process it should not go for approval. If country is having approval it should go to approval process. We are maintaining separate table for this.


2) HRManagerApprovalCheck is the script include name I am using


changed script to ApprovalCheck: function();


-- is it working now?


No still returning null value