- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2017 07:28 PM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2017 11:35 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2017 08:09 PM
Try the below: (untested though, but will give you idea)
=============================================
//start of Client Script:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
function onload/onChange() {
var userDet = g_form.getReference('openedfor', callBackFunction); //below
//Glide Ajax
var ga = new GlideAjax('HRManagerApprovalCheck'); //Script Include
ga.addParam('sysparm_name','ApprovalCheck'); //function name within Script Include
ga.addParam('sysparam_userDet', userDet); //pass the parameter
ga.getXML(GetCountryDetails);
}
function callBackFunction(userDet) {
if (userDet.country != '')
return userDet.country;
}
function GetCountryDetails(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
//end of the Client Script
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Script Include
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ApprovalCheck: function() {
var userDet = this.getParameter('sysparam_userDet');
var countryapp='';
var user = new GlideRecord('u_hr_country_and_approval_lookup');
user.addQuery('u_country', userDet );
user.query();
if (user.next()) {
countryapp=user.u_line_manager_approval_required;
}
return countryapp;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2017 02:49 AM
Hi Ravi,
Could you provide an update on your issue?
Has it resolved?
Any of the thread was Helpful?
Thanks,
Samiul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2017 07:46 PM
Please change the highlighted line number userDet should be a variable not a string to pass to ga.addParam
var userDet = g_form.getReference('openedfor');
var ga = new GlideAjax('HRManagerApprovalCheck');
ga.addParam('sysparm_name','ApprovalCheck');
ga.addParam('sysparam_userDet',userDet); //ga.addParam('sysparam_userDet','userDet');
ga.getXML(GetCountryDetails);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2017 08:03 PM
not working, still returning null value

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2017 08:39 PM
I think, below highlighted line is wrong.
getUserData: function(){
var userDet = this.getParameter('sysparam_userDet');
var det = userDet.country; //I don't think this will work to get the country, you need to glide the record first on table to get the country details first then based upon that try to get the required details.
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.toString(); //Adding toString() here
}
return countryapp;
}