About

Tuesday, 19 April 2022

For all closed REQ/RITM and CTASK, correct closing date should be updated and active = false

 

STRY0837900. For all closed REQ/RITM and CTASK, correct closing date should be updated and active = false

SCRIPT INCLUDE

var AZAutoUpdateClosedDate = Class.create();

AZAutoUpdateClosedDate.prototype = {

    initialize: function() {},

    updateClosedDate: function(sysId, c_date) {

 

        var gr_screq = new GlideRecord('sc_req_item');

        gr_screq.addQuery('request', sysId);

        gr_screq.query();

        while (gr_screq.next()) {

            if (gs.nil(gr_screq.closed_at)) {

                gr_screq.closed_at = c_date;

                gr_screq.setWorkflow(false);

                gr_screq.update();

            }

            var gr_task = new GlideRecord('sc_task');

            gr_task.addQuery('request_item', gr_screq.sys_id);

            gr_task.query();

            while (gr_task.next()) {

                if (gs.nil(gr_task.closed_at)) {

                    gr_task.closed_at = c_date;

                    gr_task.setWorkflow(false);

                    gr_task.update();

                }

            }

        }

    },

 

    type: 'AZAutoUpdateClosedDate'

};

 

FIX SCRIPT

var date1 = new GlideDateTime("2020-12-31 20:59:59");

var date2 = new GlideDateTime("2019-12-31 20:59:59");

var date3 = new GlideDateTime("2018-12-31 20:59:59");

var date4 = new GlideDateTime("2017-12-31 20:59:59");

var date5 = new GlideDateTime("2016-12-31 20:59:59");

 

var gr_req = new GlideRecord('sc_request');

gr_req.addEncodedQuery('closed_atISEMPTY^active=false^sys_created_onONOne year ago@javascript:gs.beginningOfOneYearAgo()@javascript:gs.endOfOneYearAgo()');

gr_req.query();

while(gr_req.next()){

               if(new GlideTime("2020-01-01 00:00:00") <= gr_req.sys_created_on && new GlideTime("2020-12-31 23:59:59") >= gr_req.sys_created_on)

                              {

                                             gr_req.closed_at = date1;

                                             gr_req.setWorkflow(false);

                                             gr_req.update();

                                            

                                             new AZAutoUpdateClosedDate().updateClosedDate(gr_req.sys_id.toString(), date1);

                              }

               else if(new GlideTime("2019-01-01 00:00:00") <= gr_req.sys_created_on && new GlideTime("2019-12-31 23:59:59") >= gr_req.sys_created_on)

                              {

                                             gr_req.closed_at = date2;

                                             gr_req.setWorkflow(false);

                                             gr_req.update();

                                            

                                             new AZAutoUpdateClosedDate().updateClosedDate(gr_req.sys_id.toString(), date2);

                              }

}

No comments:

Post a Comment