Before query business rule based on current record values

Pavan Yakkala1
Kilo Explorer

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

20 REPLIES 20

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

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

Pavan, You didn't answer my question about the current table?

 

Can you please share result of current.getTableName()


Thanks & Regards,
Vasanth

Hi Vasantharajan,

The table name is Risk (risk) and same is getting displayed for above line

find_real_file.png

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