Add additional comments via script on requested items by disabling notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 02:18 AM
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
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 02:22 AM
Hi
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();
}
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 02:40 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 02:50 AM
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);
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 03:37 AM
Can't I do this with scheduled job?