SPEntryPage in a Scoped App - session.getProperty(*); not working in Scope
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2018 09:36 PM
Hi Team,
I'm writing a Scoped App to replace the SPEntryPage script include function so that I can have ultimate flexibility around which Service Portal a given user will be directed to - a dedicated "Portal Redirect App". Hopefully If I can get it working I'll share it on Github/SN Share so that others can use it.
I've built a "Redirect Rule table" that contains a Portal Reference along with a condition that a user could meet for one of the user-related tables (sys_user, sys_user_grmember, sys_user_has_role are the ones I've targeted).
I've written a utility Script Include that retrieves the current user's Sys ID, then loops through all the rules to built a query against the relevant table in ascending order until it finds one that matches for the user. Once it finds a rule, it retrieves the url suffix and landing page for the user, and uses that to drive the "getLoginURL" and "getFirstPageURL" functions in my cloned SPEntryPage script. The Redirect Rule Script runs great, but I've hit some scoping problems with the original OOTB code.
In the OOTB SPEntryPage Script, the function getFirstPageURL has the following code:
getFirstPageURL: function() {
var session = gs.getSession();
this.logProperties('before', session);
// has roles and is not a Service Portal page - go to UI16
var nt = session.getProperty("nav_to");
I have a problem with the getProperty("nav_to") line - Because my app is scoped, I get a fencing error:
"TypeError: Cannot find function getProperty in object com.glide.script.fencing.ScopedGlideSession@######."
It's looking like every time I try to do a getProperty on that "getSession" object, I'll hit these scope issues... I'm a bit hazy on exactly what these properties do in the context of this script - I can see that it gets called a few times - for properties called nav_to and login_redirect - Any thoughts on what I can do here?
Is it necessary to retrieve these properties? (it looks like it!)
Is there some way to allow this like you can when you override the client script restrictions in Scoped apps?
I'm hoping to keep the code all "in Scope" but in the worst case, if I need to have a separate Script include in the global scope so I can access global functions, I could include it - it's just not as neat...
Cheers,
Kevin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 09:35 PM
Ok, so I think I've come to the conclusion that the gs.getSession().getProperty() function is just not available in Scoped Apps.
I used the Xplore scripting tool (which is AMAZING) to explore all the functions available in scope, and it just doesn't look possible.
As a workaround, I've built my Portal Redirector App so that it has a sample of an alternate SPEntryPage Script Include, and have documented that anyone using the app will need to create their own version of the Global Scoped SPEntryPage script.
BTW - if anyone wants a reasonably flexible Service Portal Redirect Application for defining custom redirect rules based on User Group Membership, Roles or record values, here's my app on Github: https://github.com/milligna/sn-portal-redirector.git
And here the quick and dirty Wiki for how to use it:
https://github.com/milligna/sn-portal-redirector/wiki/Welcome-to-my-ServiceNow-Portal-Redirector
If anyone wanted to try it out I'd be more than happy to hear what people think.