How to set "Cases assigned to me" notification onto the CSM Portal header menu like Approval?

Aki18
Tera Contributor

Just like OOTB "Approval" header menu on the Portal, I would like to set a menu that shows Cases assigned to me with number.

Could someone please advise me on how to create the header menu and what kind of script required?

 

Aki18_0-1665467522318.png

 

Best Regards,

Aki

1 ACCEPTED SOLUTION

U_Viswa
Mega Sage

Hi Aki,

 

Go to Service portal > Menus 

Open the Header Menu which you want to create the menu item.

On the new Menu page Select Type as Scripted List

// maximum number of entries in this Menu
var max = 10;
var t = data; 
t.items = [];

var u = gs.getUser().getID();

// use record watchers to tell header when to update dropdown counts
t.record_watchers = [];
t.record_watchers.push({'table':'incident','filter':'active=true^assigned_to=' + u});

var z = new GlideRecord('incident');
z.addQuery('assigned_to', u);
z.addQuery('active','true');
z.orderByDesc('sys_updated_on');
z.setLimit(max);
z.query();
while (z.next()) {
  var a = {};
  $sp.getRecordValues(a, z, 'short_description,sys_id,number,sys_updated_on,description');
  if (z.short_description.nil())
    a.short_description = "(No description)";
  a.__table = z.getTableName();
  a.type = 'record';
  a.__page = 'ticket';
  t.items.push(a);
}

var hrcCount = 0;
var hrRec = new GlideAggregate('incident');
hrRec.addQuery('assigned_to', u);
hrRec.addQuery('active','true');
hrRec.addAggregate('COUNT');
hrRec.query();
if(hrRec.next())
{
  hrcCount = hrRec.getAggregate('COUNT');
}

t.items.sort(function(a, b) {
  return b.sortOrder - a.sortOrder;
});
t.items = t.items.slice(0, max); // only want first 30
t.count = hrcCount;
if(hrcCount == "0")
{
  t.count = "0";
}
//var link = {title: gs.getMessage('View All Incidents'), type: 'link', href: '?id=my_requests', items: []};//
//t.items.unshift(link);

 

U_Viswa_0-1665471820137.png

 

 

Try. something similar to above code it will give drop down menu with record selection

Change the table name and if needed add more conditons.

Try and Let me know

Thanks

Viswa

 

 

View solution in original post

7 REPLIES 7

Martin Ivanov
Giga Sage
Giga Sage

Hello. Go to your portal and open the Header menu record from it. Then scroll down to the related lists - you will see that Approvals is a scripted list. You can duplicate it and change the script in way that it filters the records you want. In your case Cases assigned to me (glide record to the cases table, add query - assigned to me is gs.getUserID()).

MartinIvanov_0-1665468404397.png

 


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

Sai Kumar B
Mega Sage
Mega Sage

@Aki18 

1.) Go to menu items (sp_instance_menu) table

2.) Choose your CSM menu

3.) Open the menu record in the related list and create a menu item with the name My cases 

4.) You can refer to the following sample, the following menu item is created to show "My Groups" in the OOB Service Portal Header menu

a) You can set the table as a case

b.) You can set the filter to show the case records related to you
c.) You can also set an icon

 

SaiKumarB_0-1665468661260.png

 

 

Hi @Sai Kumar B ,

Thank you for your reply! Following your advice, I could make the header show the menu I wanted.

However, by clicking the menu, the link leads to the "ticket" Page of portal. The Page "ticket" does not have sufficient information, so I would like to make the menu lead to "form" Page. Could you let me know how to customize it to achieve this?  

Aki18_1-1665503750768.png

 

 

U_Viswa
Mega Sage

Hi Aki,

 

Go to Service portal > Menus 

Open the Header Menu which you want to create the menu item.

On the new Menu page Select Type as Scripted List

// maximum number of entries in this Menu
var max = 10;
var t = data; 
t.items = [];

var u = gs.getUser().getID();

// use record watchers to tell header when to update dropdown counts
t.record_watchers = [];
t.record_watchers.push({'table':'incident','filter':'active=true^assigned_to=' + u});

var z = new GlideRecord('incident');
z.addQuery('assigned_to', u);
z.addQuery('active','true');
z.orderByDesc('sys_updated_on');
z.setLimit(max);
z.query();
while (z.next()) {
  var a = {};
  $sp.getRecordValues(a, z, 'short_description,sys_id,number,sys_updated_on,description');
  if (z.short_description.nil())
    a.short_description = "(No description)";
  a.__table = z.getTableName();
  a.type = 'record';
  a.__page = 'ticket';
  t.items.push(a);
}

var hrcCount = 0;
var hrRec = new GlideAggregate('incident');
hrRec.addQuery('assigned_to', u);
hrRec.addQuery('active','true');
hrRec.addAggregate('COUNT');
hrRec.query();
if(hrRec.next())
{
  hrcCount = hrRec.getAggregate('COUNT');
}

t.items.sort(function(a, b) {
  return b.sortOrder - a.sortOrder;
});
t.items = t.items.slice(0, max); // only want first 30
t.count = hrcCount;
if(hrcCount == "0")
{
  t.count = "0";
}
//var link = {title: gs.getMessage('View All Incidents'), type: 'link', href: '?id=my_requests', items: []};//
//t.items.unshift(link);

 

U_Viswa_0-1665471820137.png

 

 

Try. something similar to above code it will give drop down menu with record selection

Change the table name and if needed add more conditons.

Try and Let me know

Thanks

Viswa