We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to display Incidents and Requests on Service portal,

sivakalyaan
Giga Contributor

Hello Guys 

I am new to service portal designing I need help to display the Incidents and Request on the service portal. 

I am attaching the HTML script and Server Script where i have created a widget where this function should work

I want these things to work

1....When status is Pending Approval then it should display the Notify Approver

2....Want to display the Incidents and Request Tickets in the same tablet

I have written the code successfully where i can display either REQUEST or INCIDENT but i am unable to display BOTH, 

So please help me

 

 

 

1 ACCEPTED SOLUTION

anjaneyulumuvva
Kilo Expert

Hi SivaKalyan,

 

you are retrieving data from 2 tables and preparing same format.then u can push in to one array (data.list).

and if status is Pending Approval then add one more value to list object "Notify Approval".

Please check below code. i have modified.

(function () {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */

// data.status='state';
// data.des='desc';
// data.num='numb';
// data.date='dat';
var data = {};
if (!options.maximum_entries) {
options.maximum_entries = 3;
var gr = new GlideRecord('sc_request');
var gi = new GlideRecord('incident');
gr.addQuery('opened_by', gs.getUserID());
gr.addQuery('active', 'true');
gr.orderByDesc('sys_created_on');
gr.query();
gi.addQuery('opened_by', gs.getUserID());
gi.addQuery('active', 'true');
gi.orderByDesc('sys_created_on');
gi.query();
data.count = gr.getRowCount();
data.count1 = gi.getRowCount();
data.list = [];
var recordIdx = 0;
while (gr.next()) {
if (recordIdx == options.maximum_entries)
break;

var record = {};
var STATUS = gr.getDisplayValue('request_state');
var DESCRIPTION = gr.getValue('short_description');
var NUMBER = gr.getValue('number');
var DATE = gr.getValue('opened_at');

record.status = STATUS;
record.description = DESCRIPTION;
record.number = NUMBER;
record.date = DATE;
if(STATUS =="Pending Approval"){
record.notify = "Notify Approval";
}else{
record.notify = "";
}
data.list.push(record);
}
data.list1 = [];
var recordIdx1 = 0;
while (gr.next()) {
if (recordIdx1 == options.maximum_entries)
break;

var record1 = {};
var STATUS1 = gr.getDisplayValue('u_request_state');
var DESCRIPTION1 = gr.getValue('short_description');
var NUMBER1 = gr.getValue('number');
var DATE1 = gr.getValue('opened_at');

record1.status = STATUS1;
record1.description = DESCRIPTION1;
record1.number = NUMBER1;
record1.date = DATE1;
if(STATUS1 =="Pending Approval"){
record.notify = "Notify Approval";
}else{
record.notify = "";
}
data.list.push(record1);
}

}

})();

View solution in original post

17 REPLIES 17

Hi Sir,

i have tried your script. i am able to see the desired result. please see the preview, its still shows the request or incidents but not both.

find_real_file.png

i think ur not pushing request array and incidents array to data.list ,

other wise request table don't have data. only 2 scenarios.

i am already checked in my instance ,i am getting results of 2 tables.

Hello sir good morning I tried in my instance sir still not working sir any suggestions

can u add below code in server script and check the output in browser console.

console.log(gr.getRowCount()+" - "+gi.getRowCount());

 

can u attach those result screen shots and serverscript.

Hello Sir i have attached the attachment so please help me to generate this report so please do the needful