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

Hi @Runjay Patel  Thank you very much for your response, this is working now.

 

Regards,

Tharun