I have a form which I want to gather the attachments off of and render into another form at a later step. I have gotten quite far with this, but have a few issues. The first form submits as PDF and the initial step of the workflow is a processFormSubmission from FormsService. That brings the attachments in as a list. The next step is a script step to convert the list of attachments to a map.
List attachmentList = patExecContext.getProcessDataListValue("/process_data/lsAttachments");
Map attachmentMap = new HashMap();
Iterator it = attachmentList.iterator();
Document attDoc = (Document) it.next();
String name = (String) attDoc.getAttribute("name");
The first problem that I run into is that the description seems to be missing from the document objects. I verified it is right away by looking at the variable contents with Record and Playback. If no ones has a simpler solution, I am looking at looping through the attachments in a preSubmit event on the form to save off the Descriptions. Then I have to figure out how to merge them back in within the code above.
The next problem that I run into is if there is only one attachment, the call to the render where the map variable is passed fails with a coercion exception trying to convert a Document to a Map. It seems if there is only one item in the map, it gets passed as just that item.
I added them through code. It is Description that was missing, not name. In the attachments window, there is name and description. Name is path on the objects. I thought Description in the window was name. It seems Description displays name if you don't set a description. By explicitly setting description in the code, it gets passed to the workflow. When rendered into the next form, it still appends a timestamp to the end of both name and description. In an initialize event in the form, I am looping through and clipping off the 28 characters that are appended. Name is not RW though and what is used to access them through code. I am using code to launch the attachments. I am looking at creating a cross reference table in the initialize as a work around.
The biggest issue left for me is the error when there is only one attachment in the map.
0 isn't a problem, 1 is. It isn't in the main workflow, but in a call to a Render. I added an input variable of type Map to the Render. In the Advanced tab of my Document Form, I pass the main workflow variable of type Map to the Render. I suppose I could create 2 variables in the Render, a Map and a single document. In the script step that moves the data from the List to the Map, if there is only 1, put it in the document variable instead. Then I would have to deal with it in the Render.
I just ran it again with 1 attachment and it worked. I haven't changed anything in the Render or Advanced tab of the variable, just adding in the description, I guess I won't complain unless it starts breaking again later.