We currently have a method that attaches a copy of a file to an Item when a new instance is created. The method is assigned to a server event in the Item's default workflow and locates the copy by using a hard-copied ID. I am trying to create a method that functions similarly, but always copy the most recent version of a file instead of a static version. I am working on a test item and test workflow and have encountered some issues with which I could use some help.
The code below is the same as the method that is currently in place. However, I'm getting different results. Here's the code in question:
Innovator inn = this.getInnovator();
/**** Find the Workflow Process Activity associated with this Activity ****/
Item myWorkFlowAct = inn.newItem("Workflow Process Activity","get");
myWorkFlowAct.setProperty("related_id", this.getID());
myWorkFlowAct.setAttribute("select", "source_id,source_type");
myWorkFlowAct = myWorkFlowAct.apply();
// test the result
if (myWorkFlowAct.isCollection())
return inn.newError("myWorkFlowAct is not a single item.");
else if (myWorkFlowAct.isError())
return inn.newError("myWorkFlowAct is an error.");
/**** Find the Workflow associated with this Workflow Process Activity ****/
Item myWorkFlow = inn.newItem("Workflow","get");
myWorkFlow.setProperty("related_id", myWorkFlowAct.getProperty("source_id"));
myWorkFlow.setAttribute("select","source_id,source_type");
myWorkFlow.apply();
The problem I'm having is that after calling "myWorkFlowAct = myWorkFlowAct.apply();", the related_id field is empty. My testing shows that the field isn't empty before that method call, so I'm confused at to why it's empty after it. This same code works just fine in the other method, which further adds to my confusion.
Can anyone shed some light on this issue?