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-27-2022 11:06 PM
Try this , it should work
var currentTask = current.sys_class_name;
if (!gs.hasRole('admin')) {
if (currentTask.startsWith('PRJ') == true)
current.addEncodedQuery('task.ref_pm_project.project_manager=' + gs.getUser().getID());
}
Anshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-27-2022 11:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-27-2022 11:35 PM
Can you try this?
var currentTask = current.task.getRefRecord();
var currentTaskNum = currentTask.sys_class_name;
if (!gs.hasRole('admin')) {
if (currentTaskNum == 'project')
current.addEncodedQuery('task.ref_pm_project.project_manager=' + gs.getUser().getID());
}
Anshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-27-2022 11:49 PM
Hi Anshu,
when I log for currentTaskNum, it is giving empty value and not providing task type as project.
var currentTask = current.task.getRefRecord();
var currentTaskNum = currentTask.sys_class_name;
gs.info("## task type:::"+currentTaskNum);
if (!gs.hasRole('admin')) {
if (currentTaskNum == 'project')
current.addEncodedQuery('task.ref_pm_project.project_manager=' + gs.getUser().getID());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2022 12:39 AM
You have to glide record then on that integration table with current.task.
Then fetch the value of that field in currentTaskNum
Anshu