How to call script include within ui page

Arthur7
Tera Contributor

How to call script include within ui page??

I have a script include like below:
#########

var GetValue = Class.create();

GetValue.prototype = Object.extendsObject(AbstractAjaxProcessor, {

            configParam : function(company,fo, param) {

                          var ps = gs.getProperty('default_config_param');

                          var gr = new GlideRecord('u_config_params');

                          gr.addQuery('u_company',company);

                          gr.addQuery('u_fo_org',fo);

                          gr.addQuery('u_param_name',param);

                          gr.query();

                          if (gr.next()){

                                return gr.u_param_value;

                          }

                          else

                          {

                                return ps;

                          }

            },

      type: 'GetValue'  

  });

1 ACCEPTED SOLUTION

veeresh3
Tera Expert

Hi,



Following is the example to call the script include from the UI pages.


Change the names according to your convenient.



var ga = new GlideAjax('HelloWorld');


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


ga.addParam('sysparm_user_name',"Bob");


ga.getXMLWait();


alert(ga.getAnswer());



Thanks,


Veeresh



Please mark as correct, if it's helpfull


View solution in original post

4 REPLIES 4

sumeet_n
Kilo Guru

The same way you would call it from Client Script, just that you need to write that code in <g:evaluate> tags.



GlideAjax - ServiceNow Wiki


veeresh3
Tera Expert

Hi,



Following is the example to call the script include from the UI pages.


Change the names according to your convenient.



var ga = new GlideAjax('HelloWorld');


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


ga.addParam('sysparm_user_name',"Bob");


ga.getXMLWait();


alert(ga.getAnswer());



Thanks,


Veeresh



Please mark as correct, if it's helpfull


Arthur7
Tera Contributor

Thanks Veeresh, it works:)


Hi All,



I too have similar requirement. Here When I am calling the script include, I am getting null value. But I checked the returned value with the help of logs. It is returning correct value. Not understanding where the mistake. Please help me on this.




Script Include:



var cluster1 = Class.create();


cluster1.prototype = Object.extendsObject(AbstractAjaxProcessor,{


      initialize: function() {


 


   


      },



urlUser: function(){


  var usr = gs.getUserID();


var terr;


var TTYPE;                                  


var clu;                                


var Reg;                                  


  var gr = new GlideRecord('sys_user');


  gr.addQuery('sys_id',usr);


  gr.query();



if(gr.next())


  {


    terr=gr.u_territory;


    clu=gr.u_cluster;          


    TTYPE = gr.u_location_type;  


    Reg = gr.u_region;


  }


gs.log("ALL CLU123******"+clu);


    var url;


    if(TTYPE=="Territory"){


  url = "/incident_list.do?sysparm_query=opened_by.u_territory%3D"+ terr;


//gs.setRedirect(window.location);


    }


    else if(TTYPE=="Cluster"){


      gs.log("======INSIDE SC CLU");


      url = "/incident_list.do?sysparm_query=opened_by.u_cluster%3D"+ clu;


    //gs.setRedirect(window.location);


      //url = TTYPE+','+clu;


    }


    else if(TTYPE=="Region"){


  url = "/incident_list.do?sysparm_query=opened_by.u_region%3D"+ Reg;


    //gs.setRedirect(window.location);


    }


gs.log("ALL URLi24******"+url);


var id = clu.toString();


return id;



},




Client Script in UI page :



redirect();
function redirect(){
alert("test");
var ga = new GlideAjax('cluster1');
ga.addParam('sysparm_name','urlUser');
ga.getXML(HelloWorldParse);
//   ga.getXMLWait();


// alert(ga.getAnswer());



function HelloWorldParse(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    alert(answer);


    window.location = answer;



}


}