- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 04:33 PM - edited 05-09-2024 08:05 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 06:13 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 05:21 PM - edited 05-09-2024 06:09 PM
Hi @Snow Angel
Attached is the code to update the Records and it is working in my PDI
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 06:02 PM
That did'nt update the value. FYI start_date variable is greyed out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 06:13 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 05:50 PM - edited 05-09-2024 05:51 PM
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);