Fusion Manage Forum
Welcome to Autodesk’s Fusion Manage (formerly Fusion 360 Manage) Forum. Share your knowledge, ask questions, and explore popular Fusion Manage topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy workflowItems from one item to another

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
sten
704 Views, 11 Replies

Copy workflowItems from one item to another

 

I am trying to automatically create a new record in a different workspace and add all the workflow items from the current record to the new record.

 

I can create a new record and fill in the basic information, but I cannot get it to copy over the workfow items.

 

I have tried different methods with no luck. This is what I have now.

 

// Add all affected items in Change Order to Review Record
for (var i in item.workflowItems) {
  var additemid = item.workflowItems[i].id;
  var linked_item = loadItem(additemid);
  newItem.workflowItems.addItem(linked_item);         <<< line 29
}

 

everything works well until the last line

the linked_item variable look good.

 

Thanks,

Sten

 

Error message:

[COcreateNewReviewRecord (line 29, col 0)] org.mozilla.javascript.WrappedException: Wrapped java.lang.NullPointerException (COcreateNewReviewRecord#29)

11 REPLIES 11
Message 2 of 12
gasevsm
in reply to: sten

Hi Sten,
Is newItem a freshly spawned item in this same script where you are trying to add items to its linked/managed tab from item.workflowitems?

Martin Gasevski | Fusion 360 Team Product Manager
Message 3 of 12
sten
in reply to: gasevsm

Yes it is.
Message 4 of 12
gasevsm
in reply to: sten

Stan, the reason why you cannot add entities into tabs of newly spawned item is because the present scripting engine renders newitem as un-committed to backend yet. The script that just created the new item is still running. The workflow items that you want copied don't see where they need to be added as there isn't a new item in database. In fact the new item doesn't have tabs yet materialized. Had you referenced an existing item to copy the workflow items to, this would've worked fine as there is complete item and tab for the one adding and the ones being added.
To achieve this goal, assuming this current script is triggered by WF transition, you need to let this script finish so it commits new item to backend. In fact, i'd link new item and current item via a picklist in this script to be able to get to the reference later. Then you need to perform another independent WF transition with a separate action script that actually gets a handle to new item from the linked picklist and here do the copying of affected items from current item to referenced(new) item in that second script. This would work fine.
Regards,

Martin Gasevski | Fusion 360 Team Product Manager
Message 5 of 12
sten
in reply to: gasevsm

Ok. I now understand why it failed.
I can see how your workaround can work, although I am not crazy about it.
I will have to make a WF transition to a dummy state and a 2nd WF transition to where I really want to go.
It will work, but a little clumsy.

I wish there was a way that I could get it to automatically perform the 2nd WF transition. For example escalate at day 0.

Thank you for the help.
Message 6 of 12
gasevsm
in reply to: sten

Sten, we are presently discussing a scripting engine model where this manipulation with newly spawned items can be done in the same single script that made the spawning (eg. adding it to other spawned/existing items' tabs as well as adding other spawned/existing items to its tabs). I have no expections to set or timeline to share with this forum just yet; we just started noodling on the concept overall. I am convinced this would address your needs, if or when it becomes available.

Regards,


Martin Gasevski | Fusion 360 Team Product Manager
Message 7 of 12
sten
in reply to: gasevsm

Sounds good.
As an engineer I can appreciate the technical challenges you are up against, however I hate to add extraneous steps to a workflow when I know that every end users / auditor will question the reason for it.
Message 8 of 12
gasevsm
in reply to: sten

Thanks for the understanding and the patience using a 2-step approach; will keep you posted of activities.
--
MG

Martin Gasevski | Fusion 360 Team Product Manager
Message 9 of 12
zep.tyrushudson
in reply to: gasevsm

Hi Martin,

I've having trouble with this same issue but it is my understanding that the script engine can now handle chaining.  I have done this successfully with things like copying items from related items tab to a newly spawned item, but I am currently having trouble getting the workflowItems.addItem to work on a freshly spawned item.  Are workflowItems excluded from the script chaining functionality?  

Message 10 of 12
gasevsm
in reply to: sten

This should work. Please share the script error to see if can understand more.

Are you using this exact syntax?

// use the {RELATED:someItem} token at the least
var workFlowItem = item.workflowItems.addItem({RELATED:spawnedItem, CUSTOM_FIELD_1:"valueA", CUSTOM_FIELD_2:"valueB"}); // can define all custom fields here
workFlowItem.lifecycle = 'Lifecycle Transition Name';
workFlowItem.CUSTOM_FIELD_3 = 'valueC'; // or can place the custom fields afterwards, either way.

Let me know what you get,

Martin Gasevski | Fusion 360 Team Product Manager
Message 11 of 12
zep.tyrushudson
in reply to: sten

I got part of it to work...I was not using the RELATED token.

My goal is to spawn a new ECO from within an ECR, them move all items from the ECR workflowItems tab to the ECO workflowItems tab, and set the lifecycle state for each item in the ECO.

Here is the code:

for each (var ecrItem in item.workflowItems){
var ecoItem = newECOItem.workflowItems.addItem({RELATED:ecrItem.item}); //this part works...
ecoItem.lifecycle = 'Phase 3 Production to EOL'; //this returns an error, "java.lang.NullPointerException: null"
}

I can successfully set the lifecycle state with this code when I run an on demand script from within the ECO item.

Ty Hudson | Engineering Fellow | SolarCity | T: (415) 329-0767 | thudson@solarcity.com | www.solarcity.com
Message 12 of 12
gasevsm
in reply to: sten

Try this Ty - do the copying of items in the ECO instead:

1. Spawn the new ECO from the ECR and add the ECR as linked PL in the ECO.
2. Then in an onCreate script of the ECO, do this:

var crItem = item.CHANGE_REQUEST; // this is your ECR linked PL
if (crItem !== null && crItem !== undefined) {
var crItemsList = crItem.workflowItems;
for (var idx=0, crLen=crItemsList.length; idx<crLen; idx++) {
var mgItem = item.workflowItems.addItem({RELATED:crItemsList[idx].item});
mgItem.lifecycle = 'Some LcTran Name';
}
}

HTH,

Martin Gasevski | Fusion 360 Team Product Manager

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report