The CreatorCon Call for Content is officially open! Get started here.

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

Part 4. In this video i have talked about ServiceNow form, list, menu, sub-menu, application, table and more basic thing which are necessary to know. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on upcoming videos: ...
10 REPLIES 10

put logs and see where it breaks

Not able to save the incident form, when we click on save this is still loading.

 

Regards,

Tharun

Runjay Patel
Giga Sage

Hi @Tharun13 ,

 

Create Async business rule and use below code.

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) {
        current.assignment_group = previous.assignment_group;
        current.update();
    }

RunjayPatel_0-1730895955981.png

 

RunjayPatel_1-1730895987899.png

 

 

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

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

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

 

Part 4. In this video i have talked about ServiceNow form, list, menu, sub-menu, application, table and more basic thing which are necessary to know. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on upcoming videos: ...

Hi Runjay,

 

Group not changing, please help on this.

 

Regards,

Tharun

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

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

 

 

Part 4. In this video i have talked about ServiceNow form, list, menu, sub-menu, application, table and more basic thing which are necessary to know. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on upcoming videos: ...