Before query business rule based on current record values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-27-2022 10:18 PM
Hi Team,
The requirement is to limit the read of records based on a role and current task type.
For example, Risks should be displayed only if type is Project and he is project manager. For this, we need to check whether task type is Project or not from Risk table and before query business rule.
But it seems we are not able to get the task reference values in before query business rules.
Can you help with how to do this?
Please find the script in before query business rule
var currentTask = current.task.getRefRecord();
var currentTaskNum = currentTask.number;
//gs.info('##Hello:::::'+currentTaskNum); //giving empty value
if (!gs.hasRole('admin')) {
if (currentTaskNum.startsWith('PRJ') == true)
current.addEncodedQuery('task.ref_pm_project.project_manager=' + gs.getUser().getID());
}
Thanks in advance
Kind regards,
Pavan
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2022 01:04 AM
Hi,
No luck still. Is there any reason why we can't get the values from Reference fields in Before query business rules?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2022 03:38 AM
You have to do reverse
If project manager is logged in that is the current user,
query BR will display task type= project when opening the table list.
or task.sys_class_name=project in current.addEncodedQuery
Anshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2022 07:59 AM
Hi,
sorry, bit confused to understand. can you help me with how query BR will display tasktype = project which should solve the issue?
Thanks,
Pavan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2022 08:32 AM
In condition section of your Before Query BR write
gs.hasRole('it_project_manager') && gs.getSession().isInteractive()
In script section
(function executeRule(current, previous /*null when async*/) {
current.addEncodedQuery('task.sys_class_name=pm_project');
})(current, previous);
Please mark answer as correct if it helps
Anshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2022 12:32 AM
Hi
There are two OOB Read ACL which you can modify and you will be able to do with your requirement instead of creating before query BR here.
First ACL:
Navigate to link below:
https://instance.service-now.com/nav_to.do?uri=sys_security_acl.do?sys_id=10bd2e0cff021000dadaebcfebffad04
Replace "instance' with your instance name.
Now in this ACL write the code shared below:
if(gs.hasRole('it_project_manager) && current.task.sys_class_name == 'pm_project'){
answer = true;
}
else{
answer = false;
}
Use the same script in below ACL as well, link shared below:
https://instance.service-now.com/nav_to.do?uri=sys_security_acl.do?sys_id=10bd2e0cff021000dadaebcfebffad04
Replace "instance' with your instance name.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke