Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Attachments in and out of forms

Avatar

Level 6
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.



import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Iterator;

import com.adobe.idp.Document;



List attachmentList = patExecContext.getProcessDataListValue("/process_data/lsAttachments");



Map attachmentMap = new HashMap();



Iterator it = attachmentList.iterator();



while(it.hasNext()){

Document attDoc = (Document) it.next();

String name = (String) attDoc.getAttribute("name");

attachmentMap.put(name, attDoc);

}



patExecContext.setProcessDataMapValue("/process_data/attachments",attachmentMap);

attachmentList.clear();

patExecContext.setProcessDataListValue("/process_data/lsAttachments", attachmentList);



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.
4 Replies

Avatar

Level 10
How are you adding your attachments? Manually or through code?



I just tried the following script:



getDocAttribute(/process_data/@inDoc, "name")



and I got the name of the file. In my case I added the attachments manually.



Jasmin

Avatar

Level 6
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.

Avatar

Level 10
You could add a step at the beginning of the process to get the size of the list. If the size is 0 go one way which is to use a document variable. Otherwise just use the list and loop.



Jasmin

Avatar

Level 6
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.