Just remove the global. Refer to the modified script below:



var counttest = Class.create();


counttest.prototype = Object.extendsObject(AbstractAjaxProcessor, {


      counttest: function() {


              gs.info ('AAAA:This script is executing');


              var gr = new GlideRecord('incident');


              gr.query();


              if(gr.next())


                      { //Added this one


  gs.info("info");


              var datedif = gs.dateDiff(gr.sys_created_on,gs.nowDateTime(), false);


              gs.info('AAAA:'+datedif);


              return datedif;


      }


},


type: 'counttest'


});


s_kumar
Mega Contributor

Hi sidarth,



I have tried your script but now its giving following results.


1.PNG


which servicenow version are you using?


s_kumar
Mega Contributor

i am using Helsinki Version of Servicenow.


will27
Giga Contributor

You might also want to check this article out:   One of the best breakdowns of client side GlideRecord and GlideAjax ServiceNow Pro Tips — GlideRecord & GlideAjax: Client-Side Vs. Server-Side