I promised a while ago that I would compile all these steps into 1 document for easier reference, rather than watch the 3 videos that I watched and 2 other blog posts... actually, I recommend you watch all those for full understanding.
I finally had some downtime so here is your Christmas gift -
Background - this is how you would manually find the URL to the list item attachment by using the API:
/_api/web/lists/getbytitle('listname')/items(id)/AttachmentFiles
Example:
https://tenantname.sharepoint.com/sites/sitename/_api/web/lists/getbytitle('inbox')/items(9)/AttachmentFiles
This returns XML output.
If you examine the XML output, you will see the XML node for ServerRelativeUrl.
<d:ServerRelativeUrl>
/sites/sitename/Lists/inbox/Attachments/9/sig__b140684065aa3ab8fa0c307c708d8889.png
</d:ServerRelativeUrl>
NOTE* for some reason it is turning the text into an emoticon. The text should be a tag angle bracket followed by letter d then colon.
Now you have the URL to the image and can insert this image into your document template for the Generate Document action in Nintex Workflow.
https://tenantname.sharepoint.com/sites/sitename/Lists/inbox/Attachments/9/sig__b140684065aa3ab8fa0c307c708d8889.png
This is how to do it in Workflow.
Steps in Nintex Workflow for Office 365 for capturing signature and inserting into Word,
Insert Action “Set Workflow Variable”
Variable = var_Title
Value = whatever you want your document title to be (I often concatenate details from the document like first name & last name plus others).
(if you are doing a lot of other actions in your workflow, then insert an Action Set and keep all these new actions in that Action Set for better readability of your workflow)
Insert Action ‘Build Dictionary’
Add 2 items, “Content-type” and “Accept.”
For Key = “Content-type” set Type = Text and Value = application/json;odata=verbose
For Key = “Accept” set Type = Text Value = application/json;odata=verbose
Send Output to variable var_RequestHeader (a Dictionary)
Insert Action “Build String”
String = {Workflow Context:Current site URL}_api/web/lists/getbytitle('{Workflow Context:List Name}')/items({Current Item:ID})/attachmentFiles
Send Output to variable var_WebServiceURL (a text string)
Insert Action “Call HTTP Web Service”
Address = {Variable:var_WebServiceUrl}
Request Type = HTTP Get
Request Headers = select variable var_RequestHeader
Request Content = (blank)
Response Content = create variable var_ResponseContent (Dictionary)
Response Headers = select variable var_RequestHeader (or var_ResponseHeader) (Dictionary)
Response Status Code = create variable var_ResponseCode (Text)
Insert Action “Get an Item from a Dictionary”
Dictionary = var_ResponseContent
Item name or path = d/results
Output = create variable var_ResultsOutputDict (Dictionary)
Insert Action “Count Items In A Dictionary”
Dictionary = var_ResultsOutputDict
Output = create variable var_ResponseCount (Integer)
Insert Action “Run If”
Configure it to run When Workflow Variables “var_ResponseCount” is greater than 1.
Inside this If branch, Insert Action “Set Workflow Variable”
Configure it to set var_ResponseCount to 1 (this ensures it runs either 0 times or 1 time, not multiple times if somehow there are multiple responses.
(done with If branch)
Insert Action “Set Workflow Variable”
Set var_LoopCounter = 0
Insert Action “Loop N Times”
Repeat Count = var_ResponseCount
Inside loop, Insert Action “Get An Item From A Dictionary”
Dictionary = var_ResponseContent
Item name or path = d/results({Variable:var_LoopCounter})/FileName
Output = create variable var_AttachmentTitle (Text)
Still inside loop, insert Action “Do Calculation”
Set Workflow variable var_LoopCounter = var_LoopCounter + 1
Still inside loop, insert Action “Set Workflow Variable”
Variable = var_AttachmentURLrelative (Text)
Value = /Lists/{Workflow Context:List Name}/Attachments/{Current Item:ID}/{Variable:var_AttachmentTitle}
Still inside loop, insert Action “Set Workflow Variable”
Variable = var_AttachmentURL (Text)
Value = {Workflow Context:Current site URL}{Variable:var_AttachmentURLrelative}
(done with loop)
(done with Action Set for getting the image URL)
Next, upload the file into an Image Library (create one if necessary) – tip* do not include spaces when you name the image library, because you will be using the name to generate the URL later.
Insert Action “Office 365 upload file”
File to upload = “Existing SharePoint content”
set relative URL to {Variable:var_AttachmentURLrelative}
Destination site URL = {Workflow Context:Current site URL}
Connection = (create a new connection)
Folder path = (name of your image library)
File name = {Variable:var_Title}.png
Overwrite existing file = Yes
Fields = Builder
Link to uploaded file = create variable var_UploadedFileURL (text)
List item ID = select variable var_ListItemID
Upload successful = create variable var_UploadSuccessful (Boolean)
Next, generate the document (PDF) using a template built in Word. If necessary, create a document library that will store only the Word template (.docx). Create another document library to store your signed PDFs – tip* do not use spaces when naming.
Insert Action “Document Generation”
Generation type = Single PDF file (50 template limit)
Select the tab “Images” and select “Add image”
Image name = varUploadedSignatureImage
Image URL = {Variable:var_UploadedFileURL}
Select the button “Add document template”
This will open Microsoft Word to edit your template (when done with Word editing, save and close word and it will return to this page, then you can later use “Tag document” to open it again in Word for editing.
You now can populate and format your document in Word. On the right under window “Nintex Document Tagger” is all the variables you might want from your workflow – tip* it is more efficient to store everything you want in a workflow variable prior to this Document Generation step, rather than try to do list lookups within this step. It also shows your Image variable.
In the spot where you want the signature image to go, insert a “dummy” image that is about the right shape & size you want your signature image to be. Resize in Word if necessary. Then select the image, which will cause “Picture Tools” to appear at the top of Word. Select Picture Tools. Select “Selection Pane” and in that open slot insert your image variable <<Image_varUploadedSignatureImage>>
Finish your Word changes, Save file and close Word. Return to Workflow.
Back in Document Generation action,
In the Document Template section, set Output file name = {Variable:var_Title}
Output location = Document Library, select name of your library for signed PDFs.
Store output file URL in = create variable var_fileURL (Text)
Select “Save” to close the Document Generation action. Now you are done!
Save & Publish your workflow.
Other tips: set permissions appropriately so that users see only their items and their signatures, while admins can see all items. Set views appropriately to see only your own items or all items for admins.
Merry Christmas to all and to all a good night!