RITM Fix Script Help!

Snow Angel
Tera Expert

Hello all,

I need to update multiple historical RITM records where field name is start_date (a variable on RITM)  on sc_req_item, the value of the field should be updated to 2020-10-21.  Please can someone help me to fix the below script.

*I have tried th ebelow but its not updating the variable which is btw greyed out/read only.
// Define the list of RITM numbers
var ritmNumbers = 'RITM0095731';
// Update the start_date field for the specified RITM numbers
var gr = new GlideRecord('sc_req_item');
gr.addQuery('number', 'IN', RITM0095731);
gr.query();

while (gr.next()) {
    gr.start_date = '2020-10-21';
    gr.update();
}

gs.info('start_date field updated for the specified RITMs.');

 

1 ACCEPTED SOLUTION

James Chun
Kilo Patron

Hi @Snow Angel,

 

Since it's a variable, you need to use the variables object.

Replace the following 

 gr.start_date = '2020-10-21';

 

with

 gr.variables.start_date = '2020-10-21';

 

Also make sure you have the speech marks around the number when you are querying by a number.

i.e. 

gr.addQuery('number''IN', 'RITM0095731');
 
Cheers

View solution in original post

5 REPLIES 5

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Snow Angel 

Attached is the code to update the Records and it is working in my PDI

var gr = new GlideRecord('sc_req_item');
gr.addQuery('number','IN','RITM0010035');
gr.query();

while (gr.next()) {
    gr.start_date =  '2020-10-21';
    gr.update();
}

 

 

 

 

Thanks and Regards

Sai Venkatesh

That did'nt update the value. FYI start_date variable is greyed out.

Hi @Snow Angel 

You can try the below script

(function () {
    var gr = new GlideRecord('sc_req_item');
    gr.addQuery('number', 'IN', 'RITM0010035'); 
    gr.query();

    while (gr.next()) {
        gr.setValue('start_date', '2020-10-21');
        gr.update(); // Update the record
    }
})();

Thanks and Regards

Sai Venkatesh

 

 

Bert_c1
Kilo Patron

I think you need to use:

 

gr.addQuery('number''IN', 'RITM0095731'); // use quotes for a string value

 

in line 5 or, since you have a variable name ritmNumbers =  'RITM0095731', then try:

 

gr.addQuery('number', 'IN', ritmNumbers);