How to call Requested For first_name and last_name using script include and client script?

vardhini
Kilo Expert

Hi All,

I am using script Include:

var Test_include = Class.create();

Test_include.prototype = Object.extendsObject(AbstractAjaxProcessor, {

     

      getIncident:function()

      {

             

              var str;

              var category=this.getParameter('sysparm_caller_id');

              var incs= new GlideRecord('incident');

              incs.addQuery('caller_id',category);

              incs.query();

              while(incs.next())

                      {

                   

                              str=incs.caller_id.first_name;

                       

                      }

              return str;

      },

     

      type: 'Test_include'

});

and Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '') {

          return;

    }

    var ga = new GlideAjax('Test_include');

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

      ga.addParam('sysparm_caller_id',g_form.getValue('caller_id'));

//ga.addParam('sysparm_category',g_form.getValue('category'));

ga.getXML(HelloWorldParse);

function HelloWorldParse(response) {

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

      alert('Answer:' + answer);

}

but the output showing NUll Values,Can anyone help on this.

Thanks in Advance,

Vardhini.

1 ACCEPTED SOLUTION

Exactly as I implemented it.


Are you using the Service Portal by any chance?



Client script


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue === '') {


          return;


  }



  var ga = new GlideAjax('Test_include');


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


      ga.addParam('sysparm_caller_id',g_form.getValue('caller_id'));


  ga.getXML(HelloWorldParse);



  function HelloWorldParse(response) {


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


  g_form.setValue('u_some_name', answer); // u_some_name is a field I created for testing purposes. The label of the field is "Some Name"


  }


}



Script include:


var Test_include = Class.create();


Test_include.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  getIncident:function() {


       


              var str;


              var category=this.getParameter('sysparm_caller_id');


              var incs= new GlideRecord('incident');


              incs.addQuery('caller_id',category);


              incs.query();


              while(incs.next())


  gs.log('RajaV caller id is ' + category);


                      {


  str=incs.caller_id.first_name;


  gs.log('RajaV inc ' + str);


  }


              return str;


      },


      type: 'Test_include'


});


View solution in original post

9 REPLIES 9

Hi Raja,


I rechecked the code and it works.



When you set the First name field in your client script - what does the code line look like?


It should be g_form.setValue('u_first_name', answer); //if your field's name is u_first_name



If that doesn't work, add the following lines to your script include:


          while(incs.next())


  gs.log('RajaV caller id is ' + category); //your name, so it is easy to filter for in the logs


                      {


  str=incs.caller_id.first_name;


  gs.log('RajaV   inc str' + str);


  }



Let me know of the results.


harel



By the way, onChange of which field?


Kalaiarasan Pus
Giga Sage

Is the client callable checkbox checked on the script include ?


vardhini
Kilo Expert

Hi,



I checked Client callable in Script include and tied with the above code,


Still it is not working,



Harel can you show me the code how you did, I will reffer



Thanks,


vardhini


Exactly as I implemented it.


Are you using the Service Portal by any chance?



Client script


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue === '') {


          return;


  }



  var ga = new GlideAjax('Test_include');


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


      ga.addParam('sysparm_caller_id',g_form.getValue('caller_id'));


  ga.getXML(HelloWorldParse);



  function HelloWorldParse(response) {


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


  g_form.setValue('u_some_name', answer); // u_some_name is a field I created for testing purposes. The label of the field is "Some Name"


  }


}



Script include:


var Test_include = Class.create();


Test_include.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  getIncident:function() {


       


              var str;


              var category=this.getParameter('sysparm_caller_id');


              var incs= new GlideRecord('incident');


              incs.addQuery('caller_id',category);


              incs.query();


              while(incs.next())


  gs.log('RajaV caller id is ' + category);


                      {


  str=incs.caller_id.first_name;


  gs.log('RajaV inc ' + str);


  }


              return str;


      },


      type: 'Test_include'


});


vardhini
Kilo Expert

Thank you Harel, It is working fine.