Onchange glideAjax client script not working on portal

Aimee Smieth
Giga Contributor

This is the first time I have tried to use a glideAjax call in an onchange client script, so some help would be greatly appreciated!

Essentially when the portal user selects a cost centre from the drop down field, I want another field to automatically populate with info from elsewhere on that cost centre record. 

Here's my script include:

 

var ReturnUserDetails = Class.create();

ReturnUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
returnUserDetails : function() {


var temp =this.getParameter('sysparm_code');
var gr = new GlideRecord('cmn_cost_center');
gr.addQuery('code', temp);
gr.query();

if(gr.next()) {

var test = gr.account_number;

return test;


}


}
});

 

And my client script:

 

 

function onChange(control, oldValue, newValue, isLoading) {
if(isLoading){
return;
}
if(newValue != ''){

var ga = new GlideAjax('ReturnUserDetails');
ga.addParam('sysparm_name','returnUserDetails');
ga.addParam('sysparm_code',newValue);
ga.getXML(UserDetailsParse);
function UserDetailsParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer); g_form.setValue('please_select_the_appropriate_line_manager_for_authorisation_of_this_float',answer);
}
}
}

It's not working however, hopefully I am missing something simple! Please could someone offer any advice?

 

Many thanks

 

3 REPLIES 3

Tiffany Royer
Giga Guru

Are you saying that it does work on the backend, it just doesn't work on the Portal?
If that is the case, did you select it to work on All?

find_real_file.png

Allen Andreas
Administrator
Administrator

Hi,

In addition to checking the UI for this client script to actually run, you should seriously consider using log statement to check that it's all working. I'm unsure if you are saying you scripted all this and didn't do any log statements to ensure your script include is called correctly and processing, etc.?

You're also playing with fire by naming your script include and the function literally the same except for one initial case difference. I wouldn't recommend that.

You should also use "getValue" in your script include to get the appropriate value which then also strings it...else at a minimum do: gr.number.toString();

Log statements, more appropriate function naming, using setValue or getValue as standard behavior, etc. are some things to always keep in mind.

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


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

Natalia26
Kilo Contributor

Hi, 

These are the suggestions that I may have for you

  • Check if the client callable checkbox is true
  • Check if the accessible from field has the right option for you, if your client script is in a different scope select "All Application Scopes" 
  • In the Ajax call include the scope of the script include so instead of name use the API Name something like:  var ga = new GlideAjax('global.ReturnUserDetails');
  • Use logs to debug if the action is being called (gs.info() gs.debug() gs.log())
  • Your script include is missing this  type: 'ReturnUserDetails' at the end it should look like this:

var ReturnUserDetails = Class.create();
ReturnUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
returnUserDetails : function() {
var temp =this.getParameter('sysparm_code');
var gr = new GlideRecord('cmn_cost_center');
gr.addQuery('code', temp);
gr.query();

if(gr.next()) {
var test = gr.account_number;
return test;
}
},
type: 'ReturnUserDetails'
});

find_real_file.png