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);

                              }

}

Tuesday, 7 December 2021

Populate caller's name if there's any attachment in Servicenow(SNOW).

 //Display BR


function executeRule(current, previous){

g_scratchpad.email = current.caller_id.email;

g_scratchpad.hasAttachment = current.hasAttachments();

}(current, previous);


//onChange Client Script


function onChange(control, oldValue, newValue, isLoading, isTemplate){

if(isLoading || newValue === ''){

return;

}


if(g_scratchpad.hasAttachment)

alert("Email ID of caller is : "+g_scratchpad.email);

else

alert("NO attachement is in the form");

}

Monday, 29 November 2021

when problem ticket is closed then related incidents should close automatically in Servicenow(SNOW)

We need to create an after business rule in the probelm table with condition and script

/*Sample code*/


var gr = new GlideRecord('incident');

gr.addActiveQuery(); // cross check for only active incidents

gr.addQuery('problem_id',current.sys_id);

gr.query();

while(gr.next()){

gr.state = '6';

gr.close_code = 'Solved(Woek Around)';

gr.close_notes = 'The incident is resolved';

gr.update();

}


gs.addInfoMessage('The incident' +gr.number+ 'is Resolved');

Sunday, 21 November 2021

Reference Qualifier in Advance and Script Include in Servicenow(SNOW).

 On problem form, there should be a field problem owner ans user can only 

select those users in the field who has problem_manager role.


var prbFunctions = Class.create();

prbFunctions.prototype = {

    initialize: function() {},

    getprbmanagers: function() {

        var gr = new GlideRecord('sys_user_has_role');

        gr.addQuery('role', 'b573c1f9538823004247ddeeff7b12e0');

        gr.query();

        while (gr.next()) {

            var prbmanagers = prbmanagers + ',' + gr.user;

        }

        var result = 'sys_idIN' + prbmanagers;

return result;

    },

    type: 'prbFunctions'

};

Tuesday, 16 November 2021

onScript and GlideAjax in Servicenow(SNOW)

 // Script Include


cmdbDetails : function() {

var cmdbid = this.getParameter('sysparm_cmdbid');

var grC = new GlideRecord('cmdb_ci');

grC.addQuery('sys_id', cmdbid);

grC.query();

if(grC.next()){

var cmdbD = "The manufacturer is " + grC.manufacturer.getDisplayValue() +

" and asset tag is " + grC.asset_tag;

}

return cmdbD;

}


//Client Script


function onLoad(){


var ga = new GlideAjax('demoGlideAjax');

ga.addParam('sysparm_name', 'cmdbDetails');

ga.addParam('sysparm_cmdbid', g_form.getValue('cmdb_ci'));

ga.getXML(cmdbCallBack);


function cmdbCallBack(response){

var answer = response.responseXML.documentElement.getAttribute('answer');

alert(answer);

}

}