How to Display results from a script in a table (or similar)

riaz_mansuri
Kilo Guru

Hi,

I have a script which runs fine and displays the results well in the scripts Background.

How do I display the script results in service now as a page and have this script run daily?

   

var dupRecords = [];

    var gaDupCheck1 = new GlideAggregate('cmdb_ci_computer');

    gaDupCheck1.addQuery('model_category','laptop');

    gaDupCheck1.addAggregate('COUNT', 'asset_tag');

    gaDupCheck1.groupBy('asset_tag');

    gaDupCheck1.addHaving('COUNT', '>', 1);

    gaDupCheck1.query();

    while (gaDupCheck1.next()) {

          dupRecords.push(gaDupCheck1.asset_tag.toString());

    }

    gs.print(dupRecords);

 

Does not have to be anything fancy as long as it displays the results.

Thanks,

Riaz

1 ACCEPTED SOLUTION

Please replace 28 line with </li>.



Also, I agree with Kalai on this.


View solution in original post

14 REPLIES 14

Gaurav Bajaj
Kilo Sage

HI Riaz,



You have two options.


Either you create a UI page, add this script in <g:evaluate> and use jellly to display the result on the HTML and get the result whenever you hit the page url.


or you can create a scheduled job which will run it daily to provide you the result. You can then trigger an email for the result.



Another way would be adding this script in a dynamic block. and add it to your dashboard.



http://wiki.servicenow.com/index.php?title=Using_Content_Blocks#Dynamic_Blocks&gsc.tab=0



Thanks


Gaurav


Thanks Gaurav,



That is helpful. I think the easiest way would be to add it to a Dynamic Block.



I click New then am a little lost



Please help



find_real_file.png


Hi Riaz,



Try below script.


A basic knowledge of jelly is required for it.


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">




<g:evaluate   var="jvar_gaDupCheck1" object="true" jelly="true">



var dupRecords = [];


  var gaDupCheck1 = new GlideAggregate('cmdb_ci_computer');


  gaDupCheck1.addQuery('model_category','laptop');


  gaDupCheck1.addAggregate('COUNT', 'asset_tag');


  gaDupCheck1.groupBy('asset_tag');


  gaDupCheck1.addHaving('COUNT', '>', 1);


  gaDupCheck1.query();


  gaDupCheck1;



//commenting the below script


  // while (gaDupCheck1.next()) {


  //   dupRecords.push(gaDupCheck1.asset_tag.toString());


  // }


//gs.print(dupRecords);



</g:evaluate>



  <ul>


<j:while test="${jvar_gaDupCheck1.next()}">


<li>


${gaDupCheck1.asset_tag}


<li>


</j:while>


</j:jelly>




Once you dynamic block it created, just add in your   homepage and see for the outcome.



Thanks


Gaurav


Thanks Gaurav,



Sorry I have almost no knowledge of Jelly (very limited Java Script as well)



I get the below when I try to save.



Any ideas?



find_real_file.png