The CreatorCon Call for Content is officially open! Get started here.

Script Include not getting called

priyankapalaska
Giga Contributor

Hi,

I am trying to call a script include through client script. but it is not getting called. Please advise.

Here is my client script:

**********************************************************

var ga=new GlideAjax('CreateINC');

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

  ga.addParam('sys_userName',g_user.userID);

  ga.getXML(doSomething);

  function doSomething(response){

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

  alert(answer);

  }

*****************************************************

Script Include:

********************************************************

var CreateINC = Class.create();

CreateINC.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  initialize: function() {

  gs.log("Initialized","priyanka");

  },

  create: function(){

    gs.log("INSIDE","priyanka");

  var user=this.getParameter('sys_userName');

  gs.log("User ="+user,"priyanka");

  var inc = new GlideRecord('incident');

  inc.initialize();

  inc.short_description = 'New incident created by SR';

  inc.caller_id=user;

  var sysID=inc.insertWithReferences();

  gs.log("SYSID ="+sysID,"priyanka");

  return sysID;

  },

  type: 'CreateINC'

});

*******************************************************

In logs, I am getting initialized msg, but msg containing INSIDE is not getting. It means function is not getting called.

Client Callable is checked.

Thanks in advance.

10 REPLIES 10

still no logs and giving alert NULL


Hi,



Something to do with Initialise function. I tried your script in my instance and if i remove initialise function from script include it works fine.


Please try.



Regards,


Karthik


Exactly, you need to remove initiliaze function as you override probably the initialize function from AbstractAjaxProcessor and then it is not working properly. Just remove it. Others are also correct that all parameters passed from client should start with sysparm_.


For those interested, here is documentation where it is even explicitely mentioned that we should not override initialize method: Examples of asynchronous GlideAjax


Hi Priyanka,



The GlideAjax looks fine and the script also. And yes you can have any variable name for sending parameters to function it can be sys_userName or sysparm_userName or it can be "abc" also only care to be taken is you use the same in server side to fetch the value. Remove the initalize() method and run it again. It should work. Generally when the script has client callable check we don't use the initialize method.




Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader