
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2018 04:07 AM
I'm having some problems with my script where I want to update records that I query, but some of the doesn't update.
So what I am trying to do is that I want to reprocess transactions of Catalog orders where the items have been shipped but the orders haven’t been closed, because of an earlier bug.
The process is as follows: when an item is shipped a Delivery Note is sent from the vendor to SNOW. The Delivery note have a reference to the Request (RQ) . Then the Catalog item tasks (RQT) for that RQ automatically gets closed complete and pending status goes to shipped/delivered.
I made a script that check for pending RQTs that have a Delivery Note referring to their Request (RQ) but haven’t been closed correctly. Then the script reprocesses them. Voila, closed and done!
// Query RQTs that are Vendor orders and pending
var task = new GlideRecord('sc_task');
task.addEncodedQuery("correlation_idLIKEpending^assignment_group=9b664a1437a15a087898ab2943990ec4");
task.query();
var i = 0; // Counter
// Query all related RCMS Delivery Notes
while(task.next()){
var rcms = new GlideRecord('u_rcms_transaction');
rcms.addQuery('u_task', task.request);
rcms.addQuery('u_type', 'DeliveryNote');
rcms.query();
if (rcms.next()) {
// Reprocess Transaction on all related Delivery Notes
rcms.u_state = 'Ready';
rcms.update();
// Count REQs
i++;
gs.print(task.number);
gs.print(task.request.getDisplayValue());
}
}
gs.print("Number of Records: " + i);
Problem is, when there are more than 1 delivery note per Request, it doesn’t reprocess the 2nd delivery note. I try to run the script again but it only queries them, print them out but doesn’t reprocess them, only the 1st one.
What do I have to add / change in my script so that ALL of the delivery notes get reprocessed, not only one?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2018 05:55 AM
As a debug statement, I would add right the rcms.query() statement,
gs.info(rcms.getRowCount() + ' records read');
That will tell you if your query is right or wrong. If it's wrong, check the addQuery() statement closely. are the u_ fields correct? Are the values you are sending to them correct? Do you want task.request (the parent of the parent)? All these things can cause your query to awry.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2018 06:06 AM
Hi Richard,
Try passing in the system name for type instead of system label once. Also, as Chuck suggested the while() loop should make things work.
rcms.addQuery('u_type', 'DeliveryNote');
Thanks,
Jaspal Singh