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 12:24 AM
Is "Risk" a custom table or sn_risk_risk table?
Can you share a GlideRecord code to display the task number from Risk table here. I meant like below,
var gr = new GlideRecord("<table_name>");
gr.setLimit(10);
gr.query();
while(gr.next()){
gr.info("Task Sys_id "+ gr.getValue("<fieldname>"))
}
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2022 01:08 AM
var taskNum = '';
var taskRec = current.task;
var taskTab = new GlideRecord('task');
taskTab.addQuery('sys_id',taskRec);
taskTab.query();
if(taskTab.next())
taskNum = taskTab.number;
But, current.task is not displaying any value in before query business rule. Any idea on this would be much appreciated
THanks,
Pavan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2022 01:43 AM
Pavan, You didn't answer my question about the current table?
Can you please share result of current.getTableName()
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2022 02:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2022 03:13 AM
Can you please execute this in background script and check whether you are getting the log.
var gr = new GlideRecord("risk");
gr.setLimit(5);
gr.query();
while(gr.next()){
gr.info("Task Sys_id "+ gr.getValue("task"));
}
if not check the field name "task" in table "risk"
Thanks & Regards,
Vasanth