- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2021 07:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2021 10:57 PM
Hi,
UI Action based approach based on problem table which is related list on Incident table
1) Visit this OOB UI Action -> Edit on Global Table
URL: https://instanceName.service-now.com/nav_to.do?uri=sys_ui_action.do?sys_id=7fff4c3d0a0a0b3400ad3f1a1d613f74
Update as this so that you create new button for your related list table
a) Action name - sysverb_edit_o2m_problem
b) Condition: (new GlideRecord(current.getTableName())).canWrite() && RP.isOneToMany() && !RP.getListControl().isOmitEditButton() && current.getTableName() == 'problem'
c) Script:
var uri = action.getGlideURI();
var path = uri.getFileFromPath();
uri.set('sysparm_m2m_ref', current.getTableName());
uri.set('sysparm_collection_related_file', current.getTableName());
uri.set('sysparm_form_type', 'o2m');
uri.set('sysparm_stack', 'no');
uri.set('sysparm_query', '');
uri.set('jvar_no_filter', 'true'); // added new
action.setRedirectURL(uri.toString('sys_m2m_template.do'));
d) Do Insert and Stay
2) Now Visit the Edit button which is OOB and update the condition as this so that the OOB button is not visible for your table
URL: https://instanceName.service-now.com/nav_to.do?uri=sys_ui_action.do?sys_id=7fff4c3d0a0a0b3400ad3f1a1d613f74
Condition: (new GlideRecord(current.getTableName())).canWrite() && RP.isOneToMany() && !RP.getListControl().isOmitEditButton() && current.getTableName() != 'problem'
OOB UI Action After changes
New Edit button
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2021 11:35 PM
Hi,
so are you saying this
1) users with role A should not be able to change the filter
2) All users without role A should be able to change the filter
Can you explain this?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2021 11:40 PM
Hi,
Filter should be hide for all users except admin user. and list collector should display only active records to all users
Thank you,
Arkesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2021 12:00 AM
Hi,
You can show active records by giving the query
uri.set('sysparm_query', 'active=true');
Now coming to hiding/showing the filter you can use either of these 2 approaches
1) Create 2 Edit buttons
a) For admin user which won't have this -> uri.set('jvar_no_filter', 'true');
b) for non-admin user which has this -> uri.set('jvar_no_filter', 'true');
OR
2) UI Script I shared can be using to determine the role and hide the filters using DOM
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2021 12:17 AM
Hi I have updated my script as below and its working fine.
var uri = action.getGlideURI();
var path = uri.getFileFromPath();
uri.set('sysparm_m2m_ref', current.getTableName());
uri.set('sysparm_stack', 'no');
uri.set('sysparm_query', 'active=true');
if(gs.hasRole('admin'))
{
uri.set('jvar_no_filter', 'false');
}
else
{
uri.set('jvar_no_filter', 'true');
}
action.setRedirectURL(uri.toString('sys_m2m_template.do'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2021 12:34 AM
Nice.
I missed that part.
Glad to help.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader