Getting UI view in business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 06:20 PM
Posting the solution here for future reference.
This comes in handy when the objective is to filter the list result based on the UI view selected.
1. Ensure the BR will only be triggered if the session is interactive.
Condition: gs.isInteractive()
2. Below is the sample code snippet to be placed in the script.
***************************************************************
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('sys_ui_view');
gr.get(RP.getViewID());
if ((gs.hasRole('ntg_user') || gs.hasRole('ntg_admin')) && !gs.hasRole('admin')) {
current.addEncodedQuery('category=NTG');
} else if (!gr.name.nil() && gr.name.toString() == 'ntg_view') {
current.addEncodedQuery('category=NTG');
} else {
return;
}
})(current, previous);
***************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 09:42 PM
HI @brian_corpuz ,
I trust you are doing great.
To ensure that the business rule (BR) is triggered only when the session is interactive, you can use the following condition:
if (gs.isInteractive()) {
// Add your code here
}
Now, let's incorporate the sample code snippet into the script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('sys_ui_view');
gr.get(RP.getViewID());
if ((gs.hasRole('ntg_user') || gs.hasRole('ntg_admin')) && !gs.hasRole('admin')) {
current.addEncodedQuery('category=NTG');
} else if (!gr.name.nil() && gr.name.toString() == 'ntg_view') {
current.addEncodedQuery('category=NTG');
} else {
return;
}
})(current, previous);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 10:01 PM
Hi Amit,
Appreciate the response.
I think it is better to use the condition field to specify the gs.isInteractive()
