Expand my Community achievements bar.

processing collections

Avatar

Level 4
Hi,



I have implemented an EmailEndpoint. It polls for emails with pdf's attached.

These pdf's can have multiple attachments. Now I have been able to get these pdf's in an collection with the processFormSubmission process.



But how do I create a loop that can process all of these attachments in the List object, for example write them to a local drive or create pdf's?



And is it in the same way possible to loop throw a collection of pdf's that where attached to the email?



Thanks,



RonnyR
7 Replies

Avatar

Level 10
It's definitely possible to create a process that loop through a list.



What I would do is first have a setValue operation that gets the number of item in your list. There is an xPath expression get-collection-size() that will return you the size.



Then have a counter variable initialized to 0. Then get the element from the list that corresponds to the counter value. You can use xPath expression /process_data/yourListVar[coutner] and put it in a document variable.



Finally increment the counter and loop back to the beginning.



So you'll be able to loop throw a collection of pdf's that where attached to the email.



Jasmin

Avatar

Level 4
To put values in a map can I use something like this:

Location:

/process_data/mapTmp[/process_data/@counter]



Excpression:

/process_data/@tmpDocument



Because I want to make a loop to convert a List to a Map.



The reason is because I am processing a dynamic form with attachments and I take the data and the attachments from that form and merge the data with a static form and than add the attachments to this static form.



When processing a form the attachments need to be stored in a List variable but when rendering a form u you need a Map to add attachments to a form. Why is this anyway????!! Is this done to make it a little more dificult???!!



Greetings,



RonnyR

Avatar

Level 4
I have been trying some more for putting a value in a Map-collection:



Location:

/process_data/mapTmp

Expression:

id='/process_data/@counter', value='/process_data/tmpDocument'



Location

/process_data/mapTmp

Expression

/process_data/@counter, /process_data/tmpDocument



Location

/process_data/mapTmp[]

Expression

/process_data/@counter, /process_data/tmpDocument



Location

/process_data/mapTmp[]

Expression

'/process_data/@counter', '/process_data/tmpDocument'



Location

/process_data/mapTmp[id='/process_data/@counter']

Expression

/process_data/tmpDocument



And a lot of other ways but I always keep getting the error:

java.lang.RuntimeException: Cannot create a map entry without a key specified.



How is an Xpath excpression like this made??



I'm getting desperate here.



RonnyR

Avatar

Level 10
If you want to put something in a Map you need to specify a key. It's not indexed like a list so code like /process_data/mapTmp[/process_data/@counter] would not work since there is not key for that element. You won't be able to retrieve it.



You need to use a SetValue operation and assign the value of your document to the map entry using the following syntax : /process_data/mapTmp[@id=keyname].



You can use the same syntax to retrieve an element from the map. You just need the key and it'll return you the object.



I hope this clears things up.



Jasmin

Avatar

Level 4
So should this work:



Location:

/process_data/mapTmp[@id=/process_data/@counter]

Expression:

/process_data/tmpDocument



as the Mappings-propertie of my SetValue process?



@counter is my counter variable that I want to use as the keyValue



Grz,