2

I would like to modify a single list item, but I don't want the workflow to run, nor do I want to pause workflow for the entire list.

How can I temporarily disable workflow on a specific list item, make some changes, and then re-enable workflow on it?

Thanks.

1 Answer 1

1

You can get SPListItem via powershell, set property and update item without firing event, see example below:

#Add SharePoint PowerShell SnapIn if not already added
 if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$web  = Get-SPWeb "http://dev2"
$list = $web.Lists["MyList"]
$item = $list.Items.GetItemById(1)


$assembly = [Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");
$type = $assembly.GetType("Microsoft.SharePoint.SPEventManager");
$prop = $type.GetProperty([string]"EventFiringDisabled",[System.Reflection.BindingFlags] ([System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Static));

$prop.SetValue($null, $true, $null); #Disable event firing

$item["Title"] = "Changed withou firing events"
$item.SystemUpdate($false)

$prop.SetValue($null, $false, $null);#Enable event firing
1
  • You should always wrap it into a tra/catch.
    – Emaborsa
    Commented Jun 28, 2017 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.