View based on URL/URI

gaidem
ServiceNow Employee
ServiceNow Employee

I have been struggling to implement a solution for dynamically loading views for Incident records. The qualifier is basically the URI/URL.

New Records
View: New

Existing Records+After clicking save on a new record
View: Default

Within the CMS
View: ess

Any suggestions on how to accomplish this?

6 REPLIES 6

tony_fugere
Mega Guru

Are you using the Create New module or the New "button" on the list?

If the module, then simply force the view using the


sysparm_view=
in the URL Arguments.

For CMS this could be just as simple, too.

For instance:

https://demo.service-now.com/incident.do?sys_id=-1&sysparm_view=ess

https://demo.service-now.com/incident.do?sys_id=-1&sysparm_view=

If not, then this old wiki article may be a start to get you on your way. If you can find a way to gather the state of the form inside this funciton:

Restrict_Form_Views_by_Role

PS - Global Business Rules are "bad" technically speaking, and should be avoided whenever possible. However, I think this is one case where they are unavoidable.


gaidem
ServiceNow Employee
ServiceNow Employee

Everything works great, except for one saving the record. I can specify the view in both the CMS and Create New URL's, but when clicking save, the view sticks with the new view.



gaidem


After a bit of "hacking" against that old idea of the [table]GetViewName function idea in my previously referenced Wiki Article, I found the

gs.action
object. That's a start.

I ran this as a Global BR to figure out what is available. If you find an object, dot-walk to it to find more like I did to learn more about gs.action. I'm sure there is something possibly helpful inside of that object??



function incidentGetViewName() {
var prefix = '>>>TESTING: ';
for(var x in gs) { gs.log(prefix + x); }
for(var x in gs.action) { gs.log(prefix + x); }
}


gaidem
ServiceNow Employee
ServiceNow Employee

Wow, this was extremely helpful! Thank you!

So much to explore, I will take a look at this in the AM.