Attachments in and out of forms

Avatar

Avatar
Validate 1
Level 5
yodadobe
Level 5

Likes

12 likes

Total Posts

298 posts

Correct reply

10 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 5
yodadobe
Level 5

Likes

12 likes

Total Posts

298 posts

Correct reply

10 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
yodadobe
Level 5

15-12-2008

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.

Replies

Avatar

Avatar
Coach
Level 10
Jasmin_Charbonn
Level 10

Likes

149 likes

Total Posts

2,154 posts

Correct reply

97 solutions
Top badges earned
Coach
Give Back 1000
Give back 900
Give Back 800
Give back 600
View profile

Avatar
Coach
Level 10
Jasmin_Charbonn
Level 10

Likes

149 likes

Total Posts

2,154 posts

Correct reply

97 solutions
Top badges earned
Coach
Give Back 1000
Give back 900
Give Back 800
Give back 600
View profile
Jasmin_Charbonn
Level 10

16-12-2008

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

Avatar
Validate 1
Level 5
yodadobe
Level 5

Likes

12 likes

Total Posts

298 posts

Correct reply

10 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 5
yodadobe
Level 5

Likes

12 likes

Total Posts

298 posts

Correct reply

10 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
yodadobe
Level 5

16-12-2008

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

Avatar
Coach
Level 10
Jasmin_Charbonn
Level 10

Likes

149 likes

Total Posts

2,154 posts

Correct reply

97 solutions
Top badges earned
Coach
Give Back 1000
Give back 900
Give Back 800
Give back 600
View profile

Avatar
Coach
Level 10
Jasmin_Charbonn
Level 10

Likes

149 likes

Total Posts

2,154 posts

Correct reply

97 solutions
Top badges earned
Coach
Give Back 1000
Give back 900
Give Back 800
Give back 600
View profile
Jasmin_Charbonn
Level 10

16-12-2008

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

Avatar
Validate 1
Level 5
yodadobe
Level 5

Likes

12 likes

Total Posts

298 posts

Correct reply

10 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 5
yodadobe
Level 5

Likes

12 likes

Total Posts

298 posts

Correct reply

10 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
yodadobe
Level 5

16-12-2008

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.