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

Chuck Tomasi
Tera Patron

This is where I start sticking gs.log() statements in my script included and ensure I'm getting the output I expect in System Diagnostics> Script Log Statements. Let's make sure the server side code is being called properly and returning what you expect.


oharel
Kilo Sage

Hi Raja,



Implemented it exactly as you have written, onChange of field assignment_group (just to test...)


I am getting the first name of the caller ID.


Can you make sure you don't have a typo in ga.addParam('sysparm_name','getIncident'); in your script? because that would return Null.



I also suggest changing while to if.



harel


vardhini
Kilo Expert

Hi Harel,


Thanks for replying,


I tried by using IF , But Still Displaying [object,object] in First Name,


Can Any one check my code.



Thanks in advace,



Vardhini


vardhini
Kilo Expert

Hi All,



If I use the above code it displying like this.



snow.png



Please can any one help on this.



Regards,


Vardhini