Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Auto Close an Interaction after one Hour (60 mins) of being Opened - if it has not been updated

WazzaJC
Tera Expert

Hi Team,

I assume this is pretty straight forward to configure via a Business Rule, also would it be an Insert/Update Business Rule?

 

What would be required to configure a simple Business Rule, that auto-closes any Interaction, after one hour (60 mins) of that Interaction having been opened, provided the Interaction has not been Updated within that hour.

 

Many thanks for the guidance/advice.

 

I am looking to configure this on my PDI.

 

Kind Regard, Warwick

2 ACCEPTED SOLUTIONS

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

I don't think a Business Rule would work here as it would need to run on an update of a record, and your use case is actually about lack of updates 🙂

So I would suggest creating a scheduled job instead (sysauto_script):
Set it to Run: Periodically, let's say every 10 minutes ( I would advise against running it too frequently).

Set the script to something like this:

var closeInterval = '60'; // in minutes <-- replace this hard coded value with a system property!

function abandonedIntractions(time) {
    var interactionToClose = new GlideRecord('interaction');
	interactionToClose.addEncodedQuery('active=true^sys_updated_onRELATIVELT@minute@ago@' + time);
	interactionToClose.setValue('state', 5); // 5 = Close abandoned
	interactionToClose.updateMultiple();
}

abandonedIntractions(closeInterval);

View solution in original post

Hi,

 

You can add "^interaction_type='Phone'" to the query Laszlo provided, like:

 

interactionToClose.addEncodedQuery('active=true^sys_updated_onRELATIVELT@minute@ago@' + time + '^interaction_type=Phone');

 

You must use the field name and value for "Interaction Type = Phone". If the Interaction Type field is a choice field, then the value for "Phone" would be needed in the query.

View solution in original post

6 REPLIES 6

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

I don't think a Business Rule would work here as it would need to run on an update of a record, and your use case is actually about lack of updates 🙂

So I would suggest creating a scheduled job instead (sysauto_script):
Set it to Run: Periodically, let's say every 10 minutes ( I would advise against running it too frequently).

Set the script to something like this:

var closeInterval = '60'; // in minutes <-- replace this hard coded value with a system property!

function abandonedIntractions(time) {
    var interactionToClose = new GlideRecord('interaction');
	interactionToClose.addEncodedQuery('active=true^sys_updated_onRELATIVELT@minute@ago@' + time);
	interactionToClose.setValue('state', 5); // 5 = Close abandoned
	interactionToClose.updateMultiple();
}

abandonedIntractions(closeInterval);

Hi Laszlo,

Thanks ever so much, I am trying this solution and it is working, it is great.

 

Can I just ask one more clarification please, then your script will work perfectly for me.

 

How can I use the exact script you have above, but also add a Condition or line item that also ensures this script only runs, for when Interaction Type = 'Phone'. ?

 

So I basically need this exact script above to run, via the scheduled job, so long as the Interaction Type = Phone.

 

Thanks ever so much for your guidance.

 

Kind Regards,

Warwick

Hi,

 

You can add "^interaction_type='Phone'" to the query Laszlo provided, like:

 

interactionToClose.addEncodedQuery('active=true^sys_updated_onRELATIVELT@minute@ago@' + time + '^interaction_type=Phone');

 

You must use the field name and value for "Interaction Type = Phone". If the Interaction Type field is a choice field, then the value for "Phone" would be needed in the query.

Hi Bert,

thanks very much for that clarification, that works perfectly, I appreciate your help.

kind Regards,

 Warwick