how to update existing additional comments with new value in request table

Shilpi Sharma2
Tera Contributor

HI All,

I want to update my existing comments with new value in request table how it is possible through script for multiple records.

 

3 REPLIES 3

Murthy Ch
Giga Sage

@Shilpi Sharma 

Can you explain a bit more on your business requirement?

Where exactly you want to write the script?

Thanks,

Murthy

Thanks,
Murthy

HI Murthy,

Like while raising request i have entered my comments as "ABC" but now i want to update existing abc with "XYZ" can it is possible.

 

The journal entry for comments is stored in the sys_history_line table related to the sys_history_set table.

And you can see the record by right clicking on the form header of your record, History -> List.

var hiset = new GlideRecord('sys_history_set');
hiset.addQuery('id', record_id);
hiset.addQuery('table', record_table);
// Code to avoid duplicate logs
hiset.orderByDesc('sys_updated_on');
hiset.setLimit(1);
hiset.query();
while (hiset.next()) {
    var liset = new GlideRecord('sys_history_line');
    liset.addQuery('set', hiset.sys_id);
    liset.addQuery('field', 'comments');

    //liset.chooseWindow(windowStart, windowEnd);
  //  liset.setLimit(1);
    liset.query();
    var counter = 0;
    while (liset.next()) {
       
        if(liset.getValue('new') == "ABC"){

liset.setValue('new','XYZ');
liset.update();
        }

}

Note this is a huge table and stores the audit history of all records.

 

Kindly mark helpful/correct if this resolved your query

 

Regards

Vinayak