Background script to update additional comments for closed RITM's
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 09:08 AM
Hi,
I have a requirement from customer wherein they want to update the additional comments/work notes of around 200 closed RTIM's. So if I set the workflow(false), the work notes/additional comments get updated only on the list view of the RITM's and not on the RITM records and if I set the workflow(true), the comments do get updated but the notifications get triggered and this is not that big of an issue for the customer.
My main concern is that when I am trying to update all 200 records, only the last RITM gets updated. So at a time only one record is getting updated that is the last one in the query.
I am not very fluent with scripting, but I did try the solutions already provided in community, but nothing works.
Please help!
Script i am using:-
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('numberINRITM0474770,RITM0474562,RITM0474417,RITM0474240,RITM0474163,RITM0473853,RITM0473649,RITM0473584,RITM0473158,RITM0472588,RITM0472416,RITM0472415,RITM0472209,RITM0472117,RITM0472039,RITM0471999,RITM0471410,RITM0471389,RITM0470994,RITM0470780,RITM0470409,RITM0470328,RITM0470253');
gr.query();
while (gr.next()) {
gr.comments='SQL Server-Script executed';
gr.setWorkflow(true);
gr.autoSysFields(false);
gr.update();
}
In this case only 'RITM0470253' comments get updated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 09:41 AM - edited 09-23-2024 09:41 AM
Hi @D Sha,
Use the following script to achieve this.
Please note, it is recommended to try this again a couple of records first in Non Prod before executing against the required Req Items.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
var requested_item = new GlideRecord('sc_req_item');
requested_item.addEncodedQuery('numberINRITM0010027,RITM0000005'); //Suggest you try on a couple of requests in Non Prod environments first before executing on Prod
//requested_item.addEncodedQuery('numberINRITM0474770,RITM0474562,RITM0474417,RITM0474240,RITM0474163,RITM0473853,RITM0473649,RITM0473584,RITM0473158,RITM0472588,RITM0472416,RITM0472415,RITM0472209,RITM0472117,RITM0472039,RITM0471999,RITM0471410,RITM0471389,RITM0470994,RITM0470780,RITM0470409,RITM0470328,RITM0470253'); //Uncomment this when you are satisfied with the results
requested_item.query();
while (requested_item.next()) {
var id = requested_item.request; // store the sys_id of REQ which is related to RITM
setComment(requested_item.sys_id, "SQL Server-Script executed");
requested_item.setWorkflow(false);
requested_item.update();
}
function setComment(ritm, comm){
// Insert the text into the Journal table
var grJournal = new GlideRecord('sys_journal_field');
grJournal.initialize();
grJournal.name = "sc_req_item";
grJournal.element_id = ritm;
grJournal.element = "comments";
grJournal.value = comm;
grJournal.insert();
// Get the history set for the current record
var grHistSet = new GlideRecord('sys_history_set');
grHistSet.get('id', ritm);
// Insert History line record
var grHistLine = new GlideRecord(grHistSet.line_table);
grHistLine.initialize();
grHistLine.field = "comments";
grHistLine.label = "Additional comments";
grHistLine.setValue('new',comm);
grHistLine.user_name = gs.getUserDisplayName();
grHistLine.user_id = gs.getUserName();
grHistLine.user = gs.getUserID();
grHistLine.update_time = new GlideDateTime();
grHistLine.set = grHistSet.getUniqueValue();
grHistLine.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 11:04 AM
It's working fine in sub-prod instance but in prod getting this error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 01:40 AM
Hi @D Sha,
Hmmm, interesting. All the tables referenced in the script are OOB (Out Of Box tables). I can only assume it is data related - on line 37 the call to to "grHistSet.getUniqueValue();" uses the ritm based on the ritm numbers provided.
You've double checked the ritm numbers? Are you able to test/update against 2 or 3 values on Prod?
I appreciate the sensitivity and @Animesh Das2 also provides good advise re smaller and easily managed data sets where you can leverage the 'Update all' option.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 06:27 AM
Yes, I did try with just 5 RITM's, still the same issue.