Skip to main content

Hi,

I am using below REST end point to get all the attachments of a particular list item and storing them in a collection variable.

webURL/_api/web/lists/getbytitle('attachment%20url%20test')/items(1)/AttachmentFiles

I would like to iterate through this collection variable so that I can build an HTML string where each attachment name is displayed in its own div and I  can set the resulting HTML value into a rich text field. 

Please help.

The rest response is of the following format: ( I have FileName and Server Relative Url that I can use to build the string).

<?xml version="1.0" encoding="utf-8"?><feed xml:base="http://mysite.com/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>2806f6ee-06b1-402f-a4cd-5a8d836ca177</id><title /><updated>2017-01-20T00:32:18Z</updated><entry><id>http://mysite.com/_api/Web/Lists(guid'44c55cef-9f28-49dd-9b89-677f493f7c90')/Items(1)/AttachmentFiles('MigrationPlan_01162017.xlsx')</id><category term="SP.Attachment" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid'44c55cef-9f28-49dd-9b89-677f493f7c90')/Items(1)/AttachmentFiles('MigrationPlan_01162017.xlsx')" /><title /><updated>2017-01-20T00:32:18Z</updated><author><name /></author><content type="application/xml"><m:properties><d:FileName>MigrationPlan_01162017.xlsx</d:FileName><d:ServerRelativeUrl>/sites/techwriters/OneNote/Lists/attachment url test/Attachments/1/MigrationPlan_01162017.xlsx</d:ServerRelativeUrl></m:properties></content></entry></feed>


    

what exactly do you need help with?

parse XML? turn XML into collection? build HTML? ....

I guess you have already started to work on that. if you posted what you already have and where you got stuck it might be easier/faster to come to the solution.


I need help parsing XML and use Build String so that I can copy the HTML string into a rich text field. 

I am iterating the Attachment collection inside for loop but not sure how to build a string by parsing the XML.


Here is what I did.

1) Used Web Request Action to get a list of attachments of a list item.

2) Created two collection variables. One for storing "ServerRelativeUrl" and the other for "fileName" of the attachment.

3) Used QueryXML action to store the ServerRelativeUrls and filenames into their respective collection variables.

4) Used for loop to iterate through serverRelativeUrls to build a string with attachment file names so that when they are clicked, they open the attachment. My question is, since I have two collection variables, How do I iterate through both of them at the same time? I am stuck here...

Please help


If Parsing a json response is easier, I can return the response as JSON response.


so you have most of the work done happy.png

I haven't checked WS specification but I would say both  "ServerRelativeUrl" and "fileName"  are mandatory in response. that way you have two collections with the same number of elements and at the same index position you have data that relates to each other.

so, it's enough to iterate through one collection, save current index in a variable and then use the index to get value from the other collection.


no this is not an option - there is no support for JSON parsing in NWF at the moment.


Hi Marian,

Can you please visually show these steps?

it will be helpful.


as I've described, it's quite easy laugh.png

workflow

single steps

parse links and filenames into collections

in forEach config get current link and current index

use index to get element from other collection

result

note: to make it more obvious I've added one more entry to your XML


Thanks a lot Marian ....It works!!!

appreciate your help!!


Reply