
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 07:26 AM - edited 02-05-2025 07:27 AM
I was wondering if anyone has had a use case for a query business rule to hide an RITM after submission and it causing issues with the workflow attaching.
As an example, I have a query rule on TASK to hide a specific RITM from end users who do not have a specific role, this works fine because both the submitters and fulfillers have the role. My new use case requires that even the submitter cannot see the RITM after submission.
I've built the query rule as such:
(function executeRule(current, previous /*null when async*/ ) {
if (!gs.hasRole('ROLE GOES HERE') && current.getTableName() != 'sc_task') {
current.addEncodedQuery('cat_item!=3e73cbdadb22da50f3dfa8c913961957^ORcat_itemISEMPTY');
}
if (!gs.hasRole('ROLE GOES HERE') && current.getTableName() == 'sc_task') {
current.addEncodedQuery('request_item.cat_item!=3e73cbdadb22da50f3dfa8c913961957^ORrequest_item.cat_itemISEMPTY');
}
})(current, previous);
However, it appears that because the submitter does not have the required role it is causing issues where the workflow does not get created/attached to the RITM.
I know I could probably achieve this with ACLs but we were trying to avoid the "Records have been removed because of security constraints" message, as that caused a lot of confusion for some users last time we implemented something in that manner.
Any thoughts on how to work around wit the query rule?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 02:26 PM
So I was able to solve this myself.
I added an onAfter business rule to SC_REQ_ITEM, it triggers on insert with a filter of "cat_item =" and having it match to the appropriate catalog item,.
I then have an advanced script to re-attach a new workflow
var workflow = new Workflow();
workflow.cancel(current);
var newWorkflow = new Workflow();
current.context = newWorkflow.startFlow(new Workflow().getWorkflowFromName('WORKFLOW_NAME_GOES_HERE'), current, '');
current.update()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 07:56 AM
@Community Alums This is expected as the traditional workflow triggers on behalf of the user who submitted the request. Since the query business rule filters records for the submitter, the same is applied in case of the workflow too and hence the workflow context doesn't function.
To avoid this, I recommend you to use a Flow instead of a workflow to fulfil the RITM as the flow allows the option to trigger it as a system user.
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 10:58 AM
Sandeep,
Thank you, I have tried this method, however even with the flow set to run as system it is still not attaching the flow to the requested item when submitted by a user who cannot see the submitted item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 07:59 AM - edited 02-05-2025 08:38 AM
@Community Alums
try adding this in the business rule condition and see if that works
gs.getSession().isInteractive()
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 10:57 AM
Ankur,
Thank you for the suggestion, I just tried this but unfortunately the workflow or flow still does not attach.
I added in some messaging for testing, and when I submit the form, gs.getSession().isInteractive() returns true so the BR is still triggering,