- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 09:23 PM
Hi,
I have a request to not allow an interaction to be changed to close complete if there is no task associated with the interaction.
I am not sure which table I should be referring in the business rule. If I reference the interaction table, then I am only able to query when the state changes to closed complete. I am not able to query if the interaction related record > task is 0.
Any assistance will be appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 10:04 PM
Hello @Giuliana Martin
You can write before update business rule on interaction table as condition "state changes to Closed complete" and in script, query the related record to check if there is any record present or not.
Example script:
var grTask = new GlideRecord("task");
grTask.addEncodedQuery("SUBQUERYsys_id,document_id,interaction_related_record^interaction=" + current.sys_id + "^ENDSUBQUERY");
grTask.query();
if (!grTask.next()) {
gs.addErrorMessage("No related task!");
current.setAbortAction(true);
}
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 09:54 PM
@Giuliana Martin - Please use the Update BR on interaction table with below code to check whether any task is associated with the interaction.
It will throw error message to relate a task.
(function executeRule(current, previous /*null when async*/ ) {
var taskGr = new GlideRecord('task');
taskGr.addEncodedQuery("SUBQUERYsys_id,document_id,interaction_related_record^interaction=" + current.sys_id + "^ENDSUBQUERY");
taskGr.query();
if (!taskGr.hasNext()) {
gs.addErrorMessage("Please associate task to close the interaction record");
current.setAbortAction(true);
return;
}
})(current, previous);
Thanks & Regards,
Vasanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 10:04 PM
Hello @Giuliana Martin
You can write before update business rule on interaction table as condition "state changes to Closed complete" and in script, query the related record to check if there is any record present or not.
Example script:
var grTask = new GlideRecord("task");
grTask.addEncodedQuery("SUBQUERYsys_id,document_id,interaction_related_record^interaction=" + current.sys_id + "^ENDSUBQUERY");
grTask.query();
if (!grTask.next()) {
gs.addErrorMessage("No related task!");
current.setAbortAction(true);
}
Thank you,
Ali