Add additional comments via script on requested items by disabling notifications

Ankita Gupte
Kilo Sage

I want to add additional comment on requested items in bulk by disabling comments.

I am trying using scheduled job as below script but additional comments are not coming

var sc_req_item = new GlideRecord('sc_req_item');

sc_task_gr.addEncodedQuery("request.requested_for=javascript:gs.getUserID()^active=true^number=RITM0123312");// number of RITM on which comment shoulf go i.e. query

sc_req_item_gr.query();

while (sc_req_item_gr.next()) {
gs.log('Auto-reassign Scheduler : auto-reassigning the task record as part of request number- for '+sc_req_item_gr.getValue('req number'));

sc_req_item_gr.setValue('Additional comments','This ticket was closed unintentionally as part of a clean-up activity. As part of the correction the ticket has been re-opened at the same state, we apologize in advance for any inconvenience caused');//additional comment on RITMs
sc_req_item_gr.update();
}

 

Please guide how I can achieve this

23 REPLIES 23

Musab Rasheed
Tera Sage
Tera Sage

Hi @Ankita Gupte ,

Please use fix script instead of scheduled job. Also, your encodedquery doesn't look correct as you are trying to run only for one RITM so why don't pass sys_id of ritm instead of writing such query.? Mark my answer as correct if that helps.

var sc_req_item = new GlideRecord('sc_req_item');

sc_task_gr.addEncodedQuery("request.requested_for=javascript:gs.getUserID()^active=true^number=RITM0123312");// number of RITM on which comment shoulf go i.e. query

sc_req_item_gr.query();

while (sc_req_item_gr.next()) {
gs.print('Auto-reassign Scheduler : auto-reassigning the task record as part of request number- for '+sc_req_item_gr.getValue('req number'));

sc_req_item_gr.comments = "Add comment here";
sc_req_item_gr.setWorkflow(false);
sc_req_item_gr.update();
}
Please hit like and mark my response as correct if that helps
Regards,
Musab

There are 1977 RITM which I need to update. I will update each RITM sysid manually know.

Also I am new to fix script so should I mark it or not?

find_real_file.png

Also I am getting this pop up when running

find_real_file.png

Ok if you are confident that your encoded query is correct then go ahead, do it in lower instance, BTW for fix script just run it for one record pass sys id of RITM and run fix script by clicking on proceed if that works then run it for all and for all click on 'Proceed in Background' so that it will run in background and you can do your work. Also add a count so that you will come to know how many records are updated, please start with one record don't run for all , run for all only when you are sure, lastly when running for all first comment update() operation and check the count and if count is correct then uncomment update() and run in background.

var count=0;
var sc_req_item = new GlideRecord('sc_req_item');

sc_task_gr.addEncodedQuery("request.requested_for=javascript:gs.getUserID()^active=true^number=RITM0123312");// number of RITM on which comment shoulf go i.e. query

sc_req_item_gr.query();

while (sc_req_item_gr.next()) {
count++;

sc_req_item_gr.comments = "Add comment here";
sc_req_item_gr.setWorkflow(false);
sc_req_item_gr.update();
}
gs.print("total number of records are " +count);
Please hit like and mark my response as correct if that helps
Regards,
Musab

Can't I do this with scheduled job?