Running business rule as admin aka async not working?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 11:54 PM
I have a business rule that runs after someone inserts, updates or deletes a time card. The point is to calculate the actual personnel cost of a project in real time (or near real time). At first, I had this run as an 'after' business rule. However, when it runs, it runs with the roles of the user who submitted the time card. As time cards are locked down, the calculation only returns that users time cards, thus the entire project actual personnel cost is off. I verified my code works as if I run it through my admin account, it works just fine.
So, I need to run the biz rule as admin. The only way I know how is to run it as async. However, even if I do it as async, it still only pulls back that users time cards and not every ones on the project. Any other way to get a biz rule to run as admin?
here's the code of the biz rule:
var projectID = current.u_project_task.u_parent_project.sys_id;
var proj = new GlideRecord('pm_project');
if (!proj.get(projectID))
return;
var oldValue = proj.u_work_cost;
var newValue = 0;
// calculate expense lines
var els = new GlideRecord('fm_expense_line');
els.addQuery('task', projectID);
els.query();
while (els.next())
newValue += parseFloat(els.amount.getReferenceValue());
// calculate personnel
var rr = new GlideRecord('resource_role');
rr.get(gs.getProperty('tbc.resource.role.blended'));
var blendedRate = rr.hourly_rate;
var tcs = new GlideRecord('time_card');
tcs.addQuery('u_project_task.u_parent_project', projectID);
tcs.addQuery('state', 'NOT IN', 'Pending,Rejected');
tcs.query();
while (tcs.next())
newValue += (tcs.total * blendedRate);
// update project
var delta = oldValue - newValue;
gs.info('***** oldValue: ' + oldValue + ' - ' + newValue);
proj.u_work_cost = newValue;
proj.update();
As you can see, nothing fancy and nothing that references the logged in user. Simply the gliderecord call to time_card is only returning that users timecards not everyone, and as async, it should be, right?
I'm on istanbul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 12:22 AM
Hi Adam,
Just check whether that logged in user can view all other people time cards by doing table_name.list
there must be query business rule which must be restricting the user to only view his/her records and not all record.
read ACL could also be there.
As part of verification you can have getRowCount() to check how many records are able to fetch
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 12:26 AM
Thanks, but that's not really the point. I want to restrict users from seeing other users time cards. I do not, however, want the business rule to exclude those time cards. hence the reason to need to run the business rule as an admin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 02:01 AM
Hi Adam,
So you want that business rule not to run for admin then add following condition in the business rule.
!gs.hasRole('admin')
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 03:21 AM
no, I want it to run as admin, not for admin.