- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 02:33 AM - edited 04-19-2023 02:38 AM
Hello all,
I have a problem setting a "conditional module query".
What I am trying to achieve is the following: if a user tries to open a module the "sysparm_query" parameter should change dependent on the user role. I created a client callable Script Include with the necessary "filter" code that should be invoked once the page is loaded, but it doesnt seem to work.
An example of my Script Include would be:
myFilterScriptInclude.filterList = function (){
if (gs.hasRole('role'))
return 'sys_idIN' + '<example Sys ID>'; // <example Sys ID> could be changed to any script that would return sys_ids
}
the "Arguments" field of the module would look something like this:
This doesnt seem to work as it appears my function doenst get called. Only once I transport the "sys_idIN" from my Script Include to the module arguments field my code gets processed.
This is quite frustrating as I would like to set different list queries for different user types. As Examples something like this:
myFilterScriptInclude.filterList = function (){
if (gs.hasRole('role'))
return 'sys_idIN' + '<example Sys ID>'; // <example Sys ID> could be changed to any script that would return sys_ids
else if (gs.hasRole('some_other_role'))
return 'someFieldName=' + '<field value>'; // '<field values>' could be changed to any script that would return this value
}
Does anyone have any ideas how to achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 11:49 PM
Quite late to answer but better than never 😛
After much searching and going through many community posts I somehow stumbled onto the following post:
As such I solved my problem like this:
- Create a "Scripted REST API" with a "Scripted REST Resource" as described in the post.
- Change the code after the "gs.isLoggedIn()" condition and before the redirectTo() function declaration
- in my case the redirectLink
3. Configure in your module config
- the field "link type" to "URL (from arguments)"
- and the field "arguments" to have as value the "resource path" of your created "Scripted REST Resource" from Step 2.
And thats it. In my opinion thats the most elegant way to achieve different user experiences for different user groups without the need to manage 100 different module entries
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 02:43 AM
why not have different modules for each role and have your specific conditions?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 02:58 AM
That could be possible but on one hand I would have to many modules with the same or similar name which in turn would be horrible user experience and maintance and on the other while my conditions are initially role based they could change to anything else like if user is in a certain company or department or location, etc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 03:33 AM
I don't think the approach you are thinking will work
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 11:49 PM
Quite late to answer but better than never 😛
After much searching and going through many community posts I somehow stumbled onto the following post:
As such I solved my problem like this:
- Create a "Scripted REST API" with a "Scripted REST Resource" as described in the post.
- Change the code after the "gs.isLoggedIn()" condition and before the redirectTo() function declaration
- in my case the redirectLink
3. Configure in your module config
- the field "link type" to "URL (from arguments)"
- and the field "arguments" to have as value the "resource path" of your created "Scripted REST Resource" from Step 2.
And thats it. In my opinion thats the most elegant way to achieve different user experiences for different user groups without the need to manage 100 different module entries