I've found tons of questions where people are looking to get the URL of an attached file after the fact via CSOM or JSOM, or some other means.
I am looking to get the URL from Sharepoint Designer, and then insert that URL in an email from a Sharepoint Designer Workflow.
To clarify, I have a list where users are adding attachments (1 attachment) to their list item (within a Sharepoint 2010 environment). I have a workflow that sends an email after a new row is created, and basically prints all of the columns in the email.
Here is where I am hung up. I also want the attached item URL to be shown in the email.
I can see the structure of the URL will be:
And since I'll know the domain, site name, list name, and ID of the row created, I can build my URL a decent amount. But, I don't know the file name. If I could get the file name from Sharepoint designer, I could build the URL.
At the moment, the only thing I see within Sharepoint Designer is a boolean value if my list item has attachments or not.
To clarify, I do not want to attach the file to the email that gets sent as a part of the work flow. I'd like to link to the item that is already upload to my Sharepoint list and is attached to a specific row item.
FYI to others who might be looking for a solution to this, although I did this was a while ago, I believe this was how I solved the problem.
I ended up using a custom JS callback after the List Item was created. This callback would update the row I just created with the filename(s) as a concatenated string in a separate column.
So the logic was something like:
- User clicks "Create New", and a SP Modal window would open, with my form loaded in the modal window. (using a modal was integral, because I could attach JS listeners to its onSubmit function).
- I'd attach a listener to the modal window, so on Submit or Cancel, I'd run a function.
- If the user canceled, the function just exited.
- If the user submitted, I'd check to see if an attachment was added to the row item. If so, using JS I could get the file name(s), then concat those names together with a separator (I think I used a colon,
:, since that can't be used in a file name) into a string and write that string to an empty column within the same row.
- I'd also mark a boolean on the row to
truethat I'd check in the SP Designer Workflow. When true, my Workflow would actually run.
- The workflow would have access to that col, could split the string, and I was able to build the URL string.
The problem with this is that, I couldn't add items to the row manually. I have to use this custom Modal interface so I'd have the ability to run updates to the row via JS.
That is to say, this solution was 100% client side. I'd rather have a server side solution, so adding to the row manually or through this custom Modal interface wouldn't matter. But alas, at the time I didn't have access to change things server-side, so this client-side solution was good enough for me.