How do I make a GlideAjax call from a processor? or call Script Include without GlideAjax

nathanfirth
Tera Guru

So here is what we are trying to do, we have built a new application that uses a processor because of js_includes conflicts when using UI pages. The app works great and it's nice because it doesn't come with all the includes and additional markup thats get jammed into a UI page.

 

So now, since js_includes and prototype is not available on the page... how do I make a GlideAjax call? Or can I mimic a GlideAjax call using jQuery Ajax?

 

I can already use the JSONv2 API to access all data client side, but being able to call Script Includes would be great.

 

Any thoughts or suggestions would be greatly appreciated.

1 ACCEPTED SOLUTION

kin-corn-karn
Giga Contributor

You can use jQuery.ajax, but you'll need the g_ck token to go along with it.   Here's an quick example of how I run mine:



jQuery.ajax({


  url: 'xmlhttp.do',


  data: {


      sysparm_processor: 'ScriptIncludeName',


      sysparm_name: 'MethodName',


      sys_id: 'ParameterValue',


      table: 'ParameterValue'


  },


  headers: {


      'X-UserToken': g_ck


  },


  success: function(response) {


      console.log('received ' + response)


  }


});


View solution in original post

5 REPLIES 5

ChrisBurks
Mega Sage

Hi Nathan,



I may be wrong but I don't think from a processor you would use the GlideAjax. Instead you could do one of two things (well one of two things I know how to do. there could be more...).


  1. if you need interaction between scripts and script includes you would extend your script include as an AbstractScriptProcessor and when you call it in the processor pass in the arguments g_request, g_response, and g_processor. Using those parameters you can pass info to other script includes or scripts you call within your AbstractScriptProcessor script. For an example a script include would look like this:

              var MyTestProcessor = Class.create();


                MyTestProcessor.prototype =   Object.extendsObject(AbstractScriptProcessor, {


                            process : function() {


                                        //....more code using this.request, this.response, this.processor


                              },


                  });


               


                  and the processor looks like this:


 


                  Path: myproc   <----------(form field named path. This is the path to call your processor)


                  Script:


                                  var doMyProc = new MyTestProcessor(g_request, g_response, g_processor);   <---oops. This is an edit. my original post I forgot the arguments.


                                    doMyProc.process();



        Or



    2. You can just use a regular script include and output the data from that.



I'll be busy this weekend but on Monday if you have the time give me a call and I'll show you some working examples.


kin-corn-karn
Giga Contributor

You can use jQuery.ajax, but you'll need the g_ck token to go along with it.   Here's an quick example of how I run mine:



jQuery.ajax({


  url: 'xmlhttp.do',


  data: {


      sysparm_processor: 'ScriptIncludeName',


      sysparm_name: 'MethodName',


      sys_id: 'ParameterValue',


      table: 'ParameterValue'


  },


  headers: {


      'X-UserToken': g_ck


  },


  success: function(response) {


      console.log('received ' + response)


  }


});


That's awesome, thank you!


Hi,



im not able to make call to my script include.. can you tell what is sys_id and table. are they mandatory arguments?



thanks,


Rushit Patel