how to auto change assignment group back to previous group after 5 min if no update

Tharun13
Tera Contributor

Hi Team,

 

 

In incident table how to auto change assignment group back to previous group after 5 min if no update. 

 

Regards,

Tharun

1 ACCEPTED SOLUTION

Hi @Tharun13 

 

Use below code, I have tested it. It will work now.

    gs.sleep(5 * 1000 * 60);
    var dur = new GlideDuration();
    dur.setValue(current.sys_created_on);

    var gdt = new GlideDateTime(); //Always UTC +0

    var duration2 = new GlideDuration();
    duration2.setValue(gdt.getValue());

    var answer = duration2.subtract(dur);
    
    if (answer.getDisplayValue().split(' ')[0] >= 5) {

        var incGR = new GlideRecord('incident'); // change table name
        incGR.addQuery('sys_id', current.sys_id);
        incGR.query();
        if (incGR.next()) {
            var gr1 = new GlideRecord("sys_audit");
            gr1.addQuery("tablename", "incident"); // change table name
            gr1.addQuery("documentkey", incGR.sys_id);
            gr1.addQuery("fieldname", "assignment_group");
            gr1.orderByDesc("record_checkpoint");
            gr1.setLimit(1);
            gr1.query();
            if (gr1.next()) {
                gs.log('old group' + gr1.oldvalue);
                current.assignment_group = gr1.oldvalue;
				current.setWorkflow(false);
                current.update();
            }


        }




    }

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

 

View solution in original post

10 REPLIES 10

Deepak Negi
Mega Sage
Mega Sage

Hi


Create an after update/insert business rule. Apply gs.sleep(5*1000*60) and check if the sys_updated_on is more than 5 mins ago. If yes, then use previous.assignment_group to set it to the Assignment Group.

 

Thanks

Deepak

Hi Deepak,

 

Please provide the business rule script.

 

Regards,

Tharun

   // Delay execution to ensure it runs 5 minutes after the record was updated
    gs.sleep(5 * 1000 * 60); // 5 minutes delay

    // Check if the record's sys_updated_on timestamp is more than 5 minutes old
    var timeDifference = new GlideDateTime().getNumericValue() - current.sys_updated_on.getGlideObject().getNumericValue();

    // Check if the time difference exceeds 5 minutes (300,000 milliseconds)
    if (timeDifference > 300000) {
        // Set the assignment group back to the value from the previous state
        current.assignment_group = previous.assignment_group;
        current.update(); // Save the record with the updated assignment group
    }

Hi Deepak,

not working below script.

Tharun13_0-1730881186561.png

 

Regards,

Tharun