How can you set default view for ticket when navigating to a record from 'Requests' menu item?

chrisperry
Giga Sage

Hi,

 

I need to automatically set the view=self-service when navigating to an REQ from the 'Requests' menu item in Service Portal:

 

https://ceisandbox1.service-now.com/ceisp?id=sc_request&table=sc_request&sys_id=b41f7da84f6d76008b81...&view=self-service

 

Currently, when I click on an item from that menu item, it does not set the view parameter in the URL.

 

Is there a way to append the view parameter to the URLs returned from this scripted list menu item?  I wasn't able to see where the URL is being generated in the server script on that menu item:

 

// maximum number of entries in this Menu

var max = 30;

 

var t = data;  // shortcut

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':'service_task','filter':'active=true^opened_by=' + u});

//t.record_watchers.push({'table':'incident','filter':'active=true^caller_id=' + u});

t.record_watchers.push({'table':'sc_request','filter':'active=true^requested_for=' + u});

 

var st = new GlideRecord('service_task');

if (st.isValid()) {

  st.addActiveQuery();

  st.addQuery('opened_by', gs.getUserID());

  st.orderByDesc('sys_updated_on');

  st.setLimit(max);

  st.query();

  while (st.next()) {

    var a = {};

    $sp.getRecordValues(a, st, 'short_description,sys_id,number,sys_updated_on');

    if (st.short_description.nil())

      a.short_description = "(No description)";

    a.__table = st.getTableName();

    a.type = 'record';

    a.sortOrder = st.sys_updated_on.getGlideObject().getNumericValue();

    t.items.push(a);

  }

}

 

/*

var z = new GlideRecord('incident');

z.addActiveQuery();

z.addQuery('caller_id', gs.getUserID());

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');

  if (z.short_description.nil())

    a.short_description = "(No description)";

  a.__table = z.getTableName();

  a.type = 'record';

  a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();

  t.items.push(a);

}  

*/

 

var z = new GlideRecord('sc_request');

z.addActiveQuery();

z.addQuery('requested_for', gs.getUserID());

z.orderByDesc('sys_updated_on');

z.setLimit(max);

z.query();

while (z.next()) {

  var ritm = new GlideRecord('sc_req_item');

  ritm.addQuery('request', z.getUniqueValue());

  ritm.query();

  //if (!ritm.next())

  //  continue;

 

  var a = {};

  $sp.getRecordValues(a, z, 'sys_id,number,sys_updated_on');

  if (ritm.next())

    a.short_description = ritm.cat_item.getDisplayValue();

  else

    a.short_description = ritm.getDisplayValue("short_description") || z.getDisplayValue("short_description");

  a.__table = z.getTableName();

  a.type = 'request';

  a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();

  t.items.push(a);

}

 

t.items.sort(function(a, b) {

  return b.sortOrder - a.sortOrder;

});

t.items = t.items.slice(0, max); // only want first 30

t.count = t.items.length;

 

var link = {title: gs.getMessage('View all requests'), type: 'link', href: '?id=requests', items: []};

t.items.unshift(link); // put 'View all requests' first

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry
1 ACCEPTED SOLUTION

Hi Shembop,



I actually was able to figure this one out a while back, sorry for not posting my solution earlier!   Here's what I did:



1. Type 'sp_ng_template.list' into your filter navigator, this will bring up the list of angular templates in your instance


2. Locate the 'spDropdownTreeTemplate' record


3. Depending on the ticket type for which you are trying to specify a view, locate the relevant line of code and update the 'href=' to include the view parameter as shown in the screenshot below:



find_real_file.png


After taking the steps above, users should automatically redirect to the specified view when clicking on a ticket from the menu drop down in service portal.




Thanks,


Chris


If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

View solution in original post

7 REPLIES 7

robpickering
ServiceNow Employee
ServiceNow Employee

Christopher,



That would be an odd behavior from the Service Portal.   All form views should be "ess" or "Self Service".


If you open a different web browser, go straight to the Service Portal, authenticate, and then select an item, is the behavior the same?


Are you being taken out of the Service Portal when clicking the link?   Or is the view just wrong?


When you view the record within the system (not on Service Portal), is there a "Self Service" view present under the View menu?



-Rob


Hi Rob,



Thanks for responding.   Yes, the behavior is the same - I am not being taken out of the Service Portal; it simply displays the ticket in 'Default' view, so the view is just wrong (based on my requirements).



When I view the record within the system, there is a 'self-service' view present under the View menu.



Default view when clicking ticket from 'Requests' menu item:


default_view.PNG



Self-service view (actually named sdi_ess), which I was able to specify in the URL from the widget configuration:



self-service_view.PNG



I was able to configure that view parameter in the URL from the widget by entering this code in the server script:



url_set_widget.PNG




Thanks for your help, I appreciate it!


If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

Did you ever get a solution to this?



I had the same question.   I have a widget that I configured to open the request in my preferred page format, but I don't know how to set it to use that page to display the item when getting to the record from the requests menu option.



Thanks,


Shannon


If you figure this out, let me know. I am trying to do the same. I am directing my incidents to the form page, but with the dropdown, I can't force it there, it just goes to the ticket page.