Hello,
I am trying to delete a linked/affected item if it goes to my cancel state. I see that there are 2 fucntions on the wiki help but no examples on how to use them. Has anyone used or have examples of how to use these two functions?
item.workflowItems[i].clear()
item.workflowItems[i].remove()
Solved! Go to Solution.
Solved by jared.sund. Go to Solution.
If all the managed (linked) items need to be deleted, you can use this:
item.workflowItems.clear();
which is equivalent to
for (var i in item.workflowItems) { item.workflowItems[i].remove(); }
If you only want to delete any particular managed items based on your condition, you could do something like this:
for (var i in item.workflowItems) { if (YOUR CONDITION) { item.workflowItems[i].remove(); } }
HI and thanks for the reply. When i run the item.workflowItems.clear(); it doesnt error out but when i return to my revisoning workspace to see if the item has been deleted, it is still there. When i attempt to run the equalivent code, it get the warning that the field "remove" doesnt exist in target workspace which is what i was getting when i intially attempted to use this. Any suggestions?
Hi,
I am not trying to delete the items from the workspace. The item(s) are in a revsioisning workspace that link to the Items and BOMS workspace. When the user moves the ECO to a "CANCELLED" state, i would like to remove the items from the Linked ITEMS tab automatically opposed to the user having to go back into the tab an manully remove the items so they can used later.
Here are the steps I created to reproduce the issue:
1. Create an item X in ECO which is a revisioning workspace.
2. Under X's linked Items tab, there are ten items linked from the workspace of "Items and BOMs".
3. In the ECO's workflow, there is a state called "CANCELLED".
4. Attach an "Action Script" to the transition to state "CANCELLED".
5. The content of "Action Script" is
item.workflowItems.clear();
6. Under X's "Workflow Actions" tab, the transition to state "CANCELLED" is performed so above action script is triggered.
7. The web page is refreshed; if go to X's linked item's tab, there are no items there, all the ten items are deleted.
Could you confirm if my steps correctly replicate your situation (but only the final result is different)? Thanks!
item.workflowItems[i].remove() will remove the item #i from the workflow item list on your original item, but leave the others in place. It won't affect the workflow item itself, though.
item.workflowItems[i].clear() is not a valid function -- what you want is item.workflowItems.clear(), which will remove all of the items from the workflow item list.
If you have an item A in workspace WS_A, which has workflow items [ B1, B2, B3, B4 ] in WS_B, then item.workflowItems[2].remove() will change item A's workflow item list to [ B1, B3, B4 ], but WS_B will be unchanged (B2 will still exist, it just won't be in A's workflow items list). item.workflowItems.clear() will empty item A's workflow item list, but again, WS_B will be unchanged.
The "Field remove does not exist in the target workspace. This may be an error." message you are getting when testing item.workflowItems[i].remove() is actually a bug; that message should not be appearing for valid functions.
Tested action script containing: item.workflowItems.clear(); to remove all Affected Items from an ECO on transition to Canceled state and found it to work as expected. Validated with Aaron and is working fine.
Since you pointed that you can see the warning, I guess you might "ran" the script in the script editor page, because the warning shows up when the script is tested in the editor page. Test a script won't cause an actual run, so nothing will be changed when a script gets tested in the script editor page.