- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2024 03:48 AM
Hi,
I've written a business rule to copy a date variable from one item in an order guide (PC logon account) to all other items ordered within the order guide, but it is only working inconsistently, sometimes updates none, sometimes a few, but never all. It's a standard variable on the item on which it is populated and then in a variable set on all the other items. Trying to avoid changing the whole OG to move the field to the initial screen.
So i'm assuming something wrong with my code, any suggestions gratefully received.
BR: After Update, Table sc_req_item, condition Item = PC logon account
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 04:01 AM
If that's the issue, maybe don't trigger the BR on the sc_req_item, but on the sc_task, when cat_item = PC Logon. Or why not create a flow for it. All flows run after, but you can easily put a wait condition in it. Have the system wait for x seconds after creation of the logon item and then run through all other related items.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2024 04:46 AM
And if you try it like this:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.request);
gr.addQuery('cat_item', '!=', 'd6753956dbd6881084cfa7c7489619b0'); // Exclude PC Logon account
gr.query();
while (gr.next()) {
// Update the start_date variable for each matching request item
updateStartDateVariable(gr, current.variables.start_date);
}
})(current, previous);
function updateStartDateVariable(reqItemGr, startDate) {
var vars = new GlideRecord('sc_item_option_mtom');
vars.addQuery('request_item', reqItemGr.sys_id);
vars.query();
while (vars.next()) {
// Check if this is the start_date variable
if (vars.sc_item_option.name === 'start_date') {
vars.sc_item_option.value = startDate;
vars.sc_item_option.update();
}
}
}
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2024 05:19 AM
Thanks for the input Mark, unfortunately that doesn't seem to update the field at all 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 01:46 AM
On further testing it seems that the script(s) only work against the RITMs which are created before the PC logon account RITM, any with a higher number have the field left blank. Is there any way to ensure an order guide item is created last, or to delay the BR until the order guide has finished?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 04:01 AM
If that's the issue, maybe don't trigger the BR on the sc_req_item, but on the sc_task, when cat_item = PC Logon. Or why not create a flow for it. All flows run after, but you can easily put a wait condition in it. Have the system wait for x seconds after creation of the logon item and then run through all other related items.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark