If there is no related task on interaction, do not allow interaction to be closed

Giuliana Martin
Tera Contributor

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. 

1 ACCEPTED SOLUTION

Ahmmed Ali
Mega Sage

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);

}

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

2 REPLIES 2

Vasantharajan N
Giga Sage
Giga Sage

@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

Ahmmed Ali
Mega Sage

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);

}

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali