report widget servicenow

brendanwilson84
Kilo Guru

Hi Guys

I am using the report widget in service portal with the report as single score, it looks good. However, when the user clicks on it it takes them to list of records.

How can i stop that happening and just have it for display value

find_real_file.png

Clicking takes me to

find_real_file.png

1 ACCEPTED SOLUTION

Ah OK, I think that was recently released as ServiceNow hadn't previously included a report widget. If the OOB widget doesn't have the functionality you want then you could install the one I just shared with you, submit an enhancement request to ServiceNow or write your own widget / copy and edit the OOB widget.



If you are just after "Single Score" Reports, it's a pretty simple widget to write yourself as all it is really is a GlideRecord Query Row Count. Infact, I did just that myself a few months ago. Picture below.



find_real_file.png


find_real_file.png


View solution in original post

13 REPLIES 13

HTML Template


<div class="panel" style="text-align:center;">


  <div ng-if="options.table">


      <h4>


        {{ options.title }}


      </h4>


      <h1>


          {{ data.record_count }}


      </h1>


  </div>


    <div ng-if="!options.table">


      <h4>


        Select a table from options


        </h4>


  </div>


</div>



Server Script


(function() {


// find the table


if(options.table){


var table = new GlideRecord("sys_db_object");


table.get(options.table);



var gr = new GlideRecord(table.name.toString());


gr.addEncodedQuery(options.query)


gr.query();


data.record_count = gr.getRowCount();


}



})();



Widget Options Schema


find_real_file.png


Thank you very much Callum, very helpful


How can this be updated to update in real time similar to when you set a report on a dashboard to update in real time?


I have a post on my website with a slightly more rounded version of the code from above, Creating a simple 'Record Count' Service Portal Widget | Callum's ServiceNow Blog



If you follow that tutorial you will be at a stage where you can add the code below in the client script of the widget, that will give you a live updating record count.



function(spUtil, $scope, $timeout) {


  /* widget controller */


  var c = this;


      $scope.table = {};


      $scope.table.updated = false;


      c.last_record_count = c.data.record_count;


     


      spUtil.recordWatch($scope, c.data.table_name, c.options.encoded_query_string, function(name, data) {


              c.last_record_count = c.data.record_count;


              c.server.update().then(function(){


                      if(c.last_record_count != c.data.record_count){


                              $scope.table.updated = true;


                              $timeout(function(){


                                      $scope.table.updated = false;


                              }, 1000);


                      }


              });


      });


}