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

Hi,

No luck still. Is there any reason why we can't get the values from Reference fields in  Before query business rules?

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

Regards,
Anshu

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 

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

Regards,
Anshu

shloke04
Kilo Patron

Hi @Pavan Yakkala 

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

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke