client script with glide ajax is not working

dvass0107
Tera Contributor

Hi Friends,

I have written a Script include made client callable with glide ajax. I am trying to fetch the caller manager into short description , when caller is changed. But its give the below error.

onChange script error: TypeError: gax.addParm is not a function function () { [native code] }

 

Client Script:

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

   //Type appropriate comment here, and begin script below
   var ga = new GlideAjax("GetManager");
   ga.addParam("sysparm_name", "callerMgr");
   ga.addParam("sysparm_caller", g_form.getDisplayValue('caller_id')); // instead I have tried with newValue also but same error
   ga.getXMLAnswer(callFunc);
   function callFunc(response){
    var answer = response;
    if (answer) {
        var shortDesc = g_form.getValue('short_description');
        g_form.setValue('short_description','Manager'+answer+ ' - '+shortDesc);
    }
   }
   
Script Include;
 
var GetManager = Class.create();
GetManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    callerMgr: function() {
        var gx = this.getParameter('sysparm_caller');
        var gr = new GlideRecord("sys_user");
        if (gr.get(gx)) {
            return gr.manager.name.toString();
        }

        return '';
    },
    type: 'GetManager'
});
  Can you please help me on this?
}
12 REPLIES 12

Zach Koch
Giga Sage
Giga Sage

I'm not sure what newValue would be since I can't see what field you have this client script set to trigger on, however the data you're pulling in with what you provided here won't work. For this line

  

 ga.addParam("sysparm_caller", g_form.getDisplayValue('caller_id'));

you can't have a display value as you would need a sys ID, so you would need to use this instead

ga.addParam("sysparm_caller", g_form.getValue('caller_id'));

as your Script include needs a sys_id since you're using this line

 var gr = new GlideRecord("sys_user");
        if (gr.get(gx)) {
            return gr.manager.name.toString();
        }

 

which is looking using a sys_id.

Also, if your client script is scoped you may be running into a scoping issue. In that case take a look at this thread

Scoped App: onChange script error: TypeError: $ is not a function function () { [native code] } 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

Juhi Poddar
Kilo Patron

Hello @dvass0107 

Try this script:

onChange client script:

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

   var ga = new GlideAjax("GetManager");
   ga.addParam("sysparm_name", "callerMgr");
   ga.addParam("sysparm_caller", newValue); // use sys_id directly here
   ga.getXMLAnswer(function(response){
      if (response) {
         var shortDesc = g_form.getValue('short_description');
         g_form.setValue('short_description', 'Manager ' + response + ' - ' + shortDesc);
      }
   });
}

Script Include:

var GetManager = Class.create();
GetManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    callerMgr: function() {
        var callerId = this.getParameter('sysparm_caller');
        var gr = new GlideRecord("sys_user");
        if (gr.get(callerId) && gr.manager) {
            return gr.manager.getDisplayValue(); // safer than .name
        }
        return '';
    },
    type: 'GetManager'
});

 Note:

  • Carefully search the entire form’s Catalog Client Scripts for any addParm or any GlideAjax variable named gax.

  • It may be in a different script (onChange for another field, onLoad, etc.).

  • Fix any instance of addParm to addParam.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

 

Hi Juhi,

Copied the same and tried with sys_id  still same error,

 ga.addParam("sysparm_caller", 'd71f7935c0a8016700802b64c67c11c6'); // use sys_id directly here

Hi @dvass0107 

Have you checked the other client scripts as well?

  • Carefully search the entire form’s Catalog Client Scripts for any addParm or any GlideAjax variable named gax.

  • It may be in a different script (onChange for another field, onLoad, etc.).

  • Fix any instance of addParm to addParam.

JuhiPoddar_0-1746807218723.png

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar