- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2022 10:33 AM
I am trying to populate some Requested Item records blank fields with data from my Task table with a Fix Script. When I run the Fix Script only one record is updated and there is no data in the field. Any suggestions???
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2022 10:39 AM
Because you're saying if(grReqItem.next()) it's only going to run one time for the first RITM returned in your query. If you want to update each RITM, replace if with a while loop.
Also, I assume you're going to update the SC Task query because you're currently querying every single task and using the first record returned to update each RITM.
Let me know if this helps.
Cheers,
Dylan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2022 10:39 AM
Because you're saying if(grReqItem.next()) it's only going to run one time for the first RITM returned in your query. If you want to update each RITM, replace if with a while loop.
Also, I assume you're going to update the SC Task query because you're currently querying every single task and using the first record returned to update each RITM.
Let me know if this helps.
Cheers,
Dylan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2022 01:40 PM - edited 12-23-2022 01:41 PM
That helps with one record being processed but now it seems that I get stuck in a loop and the records are still not updating. I tried the advice to use setValue & getValue but still no luck. I think this is happening because some RITM have multiple Task assigned this means I have multiple numbers, short descriptions, & assignment groups on one RITM ultimately causing the script to stall

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2022 10:51 AM
Hi,
I've spotted 3 pointers.
First, you use an if-statement after the sc_req_item query, that means you only process the first record (if any are returned from the query).
Second, use setValue and getValue methods whenever possible (example below)
Third, when you do the sc_task query, you haven't got any limiters at all, so all records are returned, but again, only the first record found is used, and this record might not have any values that you are looking to fill. Maybe you should narrow the query a bit more?
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addEncodedQuery('your_query_here);
ritmGR.query();
while (ritmGR.next()) { // loop through all records found
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('some_field', 'some_value');
taskGR.query();
if (taskGR.next()) { // only processes the first record
var someData = taskGR.getValue('some_field'); // using getValue
ritmGR.setValue('some_field', someData); // using setValue
ritmGR.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2022 10:53 AM
Thanks for the support, please mark my response as helpful since we seem to be on the same page.