Fred Morrison’s Weblog

What Mother Never Told You About SharePoint Workflow

PowerShell Script To Display Settings Critical To Proper Operation Of DelayActivity

Posted by fredmorrison on 2008-04-02

Run this while logged on to your SharePoint server to see the current settings that may affect the proper operation of the DelayActivity in your workflows.  WARNING: Your auditor may not like the output from Job-Workflow-AutoClean. 

# PowerShell script to display various SharePoint internal settings that may affect DelayActivity event delivery
# Author: Fred Morrison
# Company: Exostar: The Trusted Workspace for Global Partner Networks - www.exostar.com
# Last Modification Date: 2008-04-02
# Name: SpGetSettings.ps1

# start by creating an alias for the stsadm command, allowing for 32-bit vs. 64-bit differences
Set-Alias -Name stsadm 	-Value $env:CommonProgramFiles'\Microsoft Shared\Web Server Extensions\12\BIN\STSADM.EXE'

#reference: http://technet.microsoft.com/en-us/library/cc424970.aspx
Write-Host "Job-Workflow"
stsadm -o getproperty -pn job-workflow -url http://localhost
Write-Host ""

#reference: http://technet.microsoft.com/en-us/library/cc262432.aspx
Write-Host "Job-Immdiate-Alerts"
stsadm -o getproperty -pn job-immediate-alerts -url http://localhost
Write-Host ""

#reference: http://technet.microsoft.com/en-us/library/cc424968.aspx
Write-Host "Job-Workflow-AutoClean"
stsadm -o getproperty -pn job-workflow-autoclean -url http://localhost
Write-Host ""

#reference: http://technet.microsoft.com/en-us/library/cc424943.aspx
Write-Host "Job-Workflow-Failover"
stsadm -o getproperty -pn job-workflow-failover -url http://localhost
Write-Host ""

#reference: http://technet.microsoft.com/en-us/library/cc263016.aspx
# NOTE: above documenation is in error - valid values seem to be "yes" or "no", not "a value between 1 and 500"
#       compare with Alerts-Maximum to see source of possible copy/paste error during creation of documentation.
Write-Host "Alerts-Limited"
stsadm -o getproperty -pn alerts-limited -url http://localhost
Write-Host ""

#reference: http://technet.microsoft.com/en-us/library/cc262842.aspx
Write-Host "Alerts-Maximum"
stsadm -o getproperty -pn alerts-maximum -url http://localhost
Write-Host ""

#reference: http://technet.microsoft.com/en-us/library/cc262968.aspx
Write-Host "Workflow-EventDelivery-Timeout"
stsadm -o getproperty -pn workflow-eventdelivery-timeout -url http://localhost
Write-Host ""

#reference http://technet.microsoft.com/en-us/library/cc261828.aspx
Write-Host "Workflow-EventDelivery-BatchSize"
stsadm -o getproperty -pn workflow-eventdelivery-batchsize -url http://localhost
Write-Host ""

#reference: http://technet.microsoft.com/en-us/library/cc262997.aspx
Write-Host "Workflow-EventDelivery-Throttle"
stsadm -o getproperty -pn workflow-eventdelivery-throttle -url http://localhost
Write-Host ""

Write-Host "Workflow-Cpu-Throttle (obsolete)"
stsadm -o getproperty -pn workflow-cpu-throttle -url http://localhost
Write-Host ""

Write-Host "Workflow-TimerJob-Cpu-Throttle (obsolete)"
stsadm -o getproperty -pn workflow-timerjob-cpu-throttle -url http://localhost
Write-Host ""

#reference: http://technet.microsoft.com/en-us/library/cc263471.aspx
Write-Host "Workitem-EventDelivery-BatchSize"
stsadm -o getproperty -pn workitem-eventdelivery-batchsize -url http://localhost
Write-Host ""

#reference: http://technet.microsoft.com/en-us/library/cc263141.aspx
Write-Host "Workitem-EventDelivery-Throttle"
stsadm -o getproperty -pn workitem-eventdelivery-throttle -url http://localhost

 

Posted in Workflow | Tagged: , , , | Leave a Comment »

Workflow Task Due Dates – Give Them The Entire Last Day To Finish Their Task

Posted by fredmorrison on 2008-01-09

Are you setting the DueDate property of your workflow tasks to a date that you pluck from an InfoPath 2007 workflow initialization form using logic similar to the following?

 // capture task due date from XSD-generated InfoPath form class module
ApproverDueDate = frmInit.ApproveDueDate;

// set up SPWorkflowProperties of the task
taskProps.StartDate = DateTime.Now;
taskProps.DueDate = ApproverDueDate;
taskProps.PercentComplete = 0.0f;

// later on, after a DelayActivity finishes waiting for the due date to arrive so it can check for incomplete tasks...
if {DateTime.Now > ApproverDueDate)
{
    // perform some actions that result in automatic task completion
}

Please realize that if ApproverDueDate is 2008-12-31, the task will be considered overdue at 2008-12-31 00:00:00, exactly one day less than what the task assignee might expect.  If you want to give the task assignee until the end of the day of the task due date to complete his task, you should change your code to something more like this:

// allow task to be completed up until 23:59:59 of the due date
ApproverDueDate = frmInit.ApproveDueDate.AddDays(1).AddSeconds(-1);

Keep the above in mind for overdue task reminder dates too!

Posted in Workflow | Leave a Comment »

Create a Discussion Thread on a Discussion Board with Author Override

Posted by fredmorrison on 2007-12-06

So, there I was, trying to figure out how to create a new Discussion Thread on a SharePoint Discussion Board using the ‘feedback’ comments from a just-completed SharePoint task. 

It’s a great way to put all the comments from each completed workflow task in a SharePoint Discussion Board, providing an easy, ‘one-stop shopping’ view of all the feedback from all the workflow participants.  They can even engage in threaded conversations, if desired.

A quick Google search and I was off to the races using SPUtility.CreateNewDiscussion.  Should have been what I call a ‘quick victory’ in terms of time and code required.  It should have been even quicker because I wrote a small, one-step ‘proof of concept’ workflow using Visual Studio 2008 to verify how things should work.  VS 2008 streamlines the time needed to go from code to running a workflow by a factor of 4:1 compared to VS 2005.

Experience tells me there is a lot that ‘Mother [Microsoft] Never Told You About <<fill in subject>>…’, and this situation, of course, was no different. 

It seems that the ‘Author’ of the conversation thread cannot be specified via the CreateNewDicussion API.  It took some digging/experimentation (mostly try this, fail, try something else, fail) – the usual pattern in other words.  Even when I thought I had the solution, I got tripped up by the ‘freaky string format syntax’ required to change the ‘Author’ (and ‘Editor’ too as it turns out) to something other than the default of ‘System Account’ (or whatever account runs the SharePoint ‘engine’). 

So what exactly was it that ‘Mother [Microsoft] Never Told You About Specifying the Author of a SharePoint Discussion Thread’?  In code, it looks like the following, paying particular attention to the string.Format syntax. 

My question to anyone who might have some insight is this: was the person that dreamed up the freaky “;#” syntax needed to set the ‘Author’ and ‘Editor’ fields on drugs at the time he/she architected that part of SharePoint?  What happened to the KISS principle on this one?  Remember: Eschew Obfuscation!

/// <summary>
/// Creates a new Discussion thread on the specified Discussion Board, while associating the creator of the thread
/// to the specified person, not the default of 'System Account'
/// (or whatever account is running the SharePoint 'engine').
/// </summary>
/// <param name="ThreadCreator">SPUser object instance of the person who should become the thread Author.</param>
/// <param name="DiscussionBoard">SPList object instance of the Discussion Board a new Discussion Thread will be added too.</param>
/// <param name="Title">String value of the title of the new Discussion Thread.</param>
/// <param name="Body">String value of the body of the new Discussion Thread.</param>
/// <returns>SPListItem instance pointing to the newly created Discussion Thread</returns>
private SPListItem CreateDiscussionThread(SPUser ThreadCreator, SPList DiscussionBoard, string Title, string Body)
{
    SPListItem returnValue = SPUtility.CreateNewDiscussion(DiscussionBoard.Items, Title);
    returnValue[SPBuiltInFieldId.Body] = Body;
    string userInformation = string.Format("{0};#{1}", ThreadCreator.ID, ThreadCreator.Name);
    returnValue[SPBuiltInFieldId.Author] = userInformation;
    returnValue[SPBuiltInFieldId.Editor] = userInformation;
    returnValue.Update();
    return returnValue;
}

Posted in Workflow | Tagged: , | 5 Comments »

SharePoint Forums

Posted by fredmorrison on 2007-11-01

Posted in Uncategorized | Leave a Comment »

Andrew Connell’s article on Features

Posted by fredmorrison on 2007-11-01

Posted in Uncategorized | Leave a Comment »