Workflow Attach Document to an Item

Can you use a SharePoint workflow to attach a document to an item?
YES!!!

What do you need to make this happen?
SharePoint Designer
ILove SharePoint actions from codeplex.

On the server(s) that your web app is running, you will need to modify the PowerShell execution policy.
set-executionpolicy Unrestricted (Use this link for more info)

In SharePoint Designer add the Execute PowerShell Script action.
Click Script and add the PowerShell script below (make the needed changes to reflect your URL)

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$web = Get-SPWeb "http://sharepointed.com/subsite/"
$filePath = "http://sharepointed.com/subsite/docs/taco.docx"

$spList = $web.lists["Your List or Library Name Here"] 
$item = $splist.GetItemById([*Add the workflows Current Item:ID here*])
$file = $web.GetFile($filePath).OpenBinary()

$item.Attachments.Add($filepath, $file)
$item.Update()

$web.Dispose()

$web = the site you are wanting to work with.
$filePath = file path to the document you are wanting to attach to the item that triggered the workflow.
$spList = List that contains the item we are attaching the document to.
$item = $splist.GetItemById() clear out the text between the (), in here you ware wanting to place ID of the item that triggered the workflow. This will tell the PowerShell script what item we are attaching the document to.

One thought on “Workflow Attach Document to an Item

Leave a Reply

Your email address will not be published. Required fields are marked *