Delegate SharePoint Workflow Task

I had this requirement to apply delegation on SharePoint workflow task, as we have in Project Server. There is no such feature for SharePoint workflow taks. The simple way to achieve this, is to change the “Assigned To” to the new user and it will be assigned to the new user and send email just like a normal workflow.

Advertisements

Deleting List Items Through PowerShell

Use the following code to delete SharePoint list items through PowerShell. This code comes handy, if you have humongous amount of data in a list and you want to delete it.

$web = Get-SPWeb http://servername/sites/sitename
$listName = "samplelist"
$list = $web.Lists[$listName]
$items = $list.Items 

Write-Host $items.Count
for($i=$items.Count-1;$i -ge 0;$i--  )
{
Write-Host $list.Items[$i].id
$list.Items[$i].Delete()
}

Redirecting User to Approval Edit Form Automatically

Add following html in a content editor of workflow task display form. This will redirect user to editable approval form.

 

<script src="/PWA/SiteAssets/RedirectToEditForm.js"></script>

the javascript file RedirectToEditForm.js should have the following code:

    var origUrl = window.location.toString();
    var editUrl = origUrl.replace("DispForm","EditForm");
    window.location = editUrl;

Note: Do not add Script tags in the file, just add code in file.

Update Projects Sites’ Write Security Option Through PowerShell

Following will iterate over all the sites within the specified site collection and updates specified lists’ write security.

#Change these variables to your site URL and list name

$site = Get-SPSite http://dhldepmweb01/PWA

$listName1 = "Assumptions and Constraints"

$listName2 = "Risks"

$listName3 = "Issues"

$listName4 = "Projects Dependent On This Project"

$listName5 = "Projects On Which This Project Depends"

#Walk through each site in the site collection

$site | Get-SPWeb -limit all| ForEach-Object {

write-output("")

#$_.Title

if(!($_.Title.ToLower().Contains("template") -or $_.URL.ToLower().Contains("template")) -And !($_.Title.ToLower().Contains("Business Intelligence Center") -or $_.URL.ToLower().Contains("Business Intelligence Center")))

{

write-output("Checking site:"+$_.Title + " URL: "+$_.URL)

#Get the list in this site

$list1 = $_.Lists[$listName1]

$list2 = $_.Lists[$listName2]

$list3 = $_.Lists[$listName3]

$list4 = $_.Lists[$listName4]

$list5 = $_.Lists[$listName5]

if($list1.WriteSecurity -eq 1 -Or $list2.WriteSecurity -eq 1 -Or $list3.WriteSecurity -eq 1 -Or $list4.WriteSecurity -eq 1)

{

#$_.URL

#Either of the following would work

write-output($list1.Title+": "+ $list1.WriteSecurity)

$list2.Title+": "+ $list2.WriteSecurity

$list3.Title+": "+ $list3.WriteSecurity

$list4.Title+": "+ $list4.WriteSecurity

$list5.Title+": "+ $list5.WriteSecurity

#write-output("about to update")

#Make the list changes

$list1.WriteSecurity = 2

$list2.WriteSecurity = 2

$list3.WriteSecurity = 2

$list4.WriteSecurity = 2

$list5.WriteSecurity = 2

#Update the list

$list1.Update()

$list2.Update()

$list3.Update()

$list4.Update()

$list5.Update()

#write-output("Site updated")

write-output("Site Updated")

}

Else

{

#write-output("Site already updated")

}

}

Else

{

write-output("Template or Explicitly defined Site not updated: "+$_.Title +" URL:"+$_.URL)

}

}

#Dispose of the site object

$site.Dispose()

Deleting List Items Through PowerShell Filtered Using CAML Query

Use the following to delete items older than the specified date in CAML below and limiting to 500 all together.

$site = new-object Microsoft.SharePoint.SPSite("<a href="http://dhldepmweb01/PWA">http://dhldepmweb01/PWA</a>")

$web = $site.rootweb

$list = $web.Lists["Project Server Workflow Tasks"]

$caml='<Where>

<Leq>

<FieldRef Name="Created" />

<Value IncludeTimeValue="TRUE" Type="DateTime">2015-12-31T02:32:20Z</Value>

</Leq>

</Where>'

$query=new-object Microsoft.SharePoint.SPQuery

$query.Query=$caml | Write-Output

$items=$list.GetItems($query)

$listItemsTotal = $items.Count;

$count=0

#Limiting the deletion till 500 count

for($x=$listItemsTotal-1;$x -ge 0 -And $count -le 500; $x--)

{

$items[$x].Delete()

$count++

}

$web.Dispose()

$site.Dispose()