Archive for August, 2006

Configuration Information for Workflows

In the workflow I’m working on, some xPaths. I don’t want to hard code them, as this is the sort of crap that always changes. However, I’m not sure where a good place to store such properties would be. I’d figured the workflow.xml file, or even features.xml, but I didn’t find information about doing this. All it’d need is a series of properties and values, but neither seems to do that.

I guess I could write an association form - but given that this workflow will only be used on one list, and that the settings shouldn’t change very often, this would be like using an anti-aircraft gun to kill a mosquito.

It is really frustrating to have simple tasks, no documentation, and no answers. I mean, come on guys, all I want to know is the right way to install a config data, and access it.

Confusing Modification Forms and State Machines

I’m building a state machine workflow for MOSS, but as part of this we need to be able to reassign tasks to other users (in case someone is ill, on holiday, etc.)

The ECM Sample Starter Kit has an example that uses an Infopath Modification form to do just that. Looking at the code for it, I can see how it has an ‘EnableWorkflowModification’ step to, well, enable a modification form, and I looked this up on the MSDN site.

The MSDN site pages I looked at here and here discuss the scope of the enabled form. However, this seems to be related to the step it is contained within a sequential workflow. This, presumably, doesn’t apply in a state machine workflow? Or maybe it applies to the whole state (i.e. the state is the scope)- which raises questions as a state might be reached by many routes, without enabling the modification.

More on Updating SharePoint Workflow Tasks

So, I’ve continued investigating my problems updating a SharePoint Workflow Task. I decided to learn about event receivers, as this is what the message was about.

Event receivers, well, receive events that happen on an item, and process them. I listed the ones on my workflow task list with the following code:

for (int j = 0; j < myList.EventReceivers.Count; j++)
{
SPEventReceiverDefinition d = myList.EventReceivers[j];
Log (d.Assembly + ” - ” + d.Class + ” - ” + d.Data + ” - ” + d.Filter + ” - ” + d.Name + ” - ” + d.Type.ToString());
}

This gave the the results:

31/08/2006 11:13:57 - Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c - Microsoft.SharePoint.Workflow.WorkflowTaskUpdateEventReceiver - - - - ItemAdding

31/08/2006 11:13:57 - Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c - Microsoft.SharePoint.Workflow.WorkflowTaskUpdateEventReceiver - - - - ItemUpdating

31/08/2006 11:13:57 - Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c - Microsoft.SharePoint.Workflow.WorkflowTaskUpdateEventReceiver - - - - ItemDeleting

31/08/2006 11:13:57 - - - - - - 32767

It turns out that there is an easier way of list the event receivers, but dumping to a log file works. Interestingly, he also had the same 32767 result, which is weird. It’s (2^15)-1, so presumably the highest value that can be represented by a 16bit signed integer - but what is it doing in my log?

Anyway, I reckon that the ItemUpdating event receiver is killing my update - but don’t effing know why.

Incidentally, this is a good article demonstrating event receivers. Shame about the bugs they’re finding, though.

Updating SharePoint ‘Workflow Tasks’

Problems doing the simplest things. I want to update a task created by the CreateTask activity, when the activity is changed. I have the following function, which is run when the Task list item is edited…

private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)
{
SPWeb mySite = new SPSite(workflowProperties.SiteId).OpenWeb(workflowProperties.WebId);
SPList myList = mySite.Lists[workflowProperties.TaskListId];
SPListItem myTask = myList.GetItemById(TaskBeforeProperties.TaskItemId);
SPUser myUser = mySite.AllUsers[e.Identity];
myTask["Assigned To"] = myUser;
myTask.Update();
}

Everything seems okay, but when I call myTask.Update(), I get the exception “An event receiver has cancelled the request.” And I’m damned if I know why.

Lock picking… …well, bumping

Interesting and slightly worrying way of Opening a lock by ‘bumping’ it

Error in SharePoint Logs - Load Workflow Assembly: System.IO.FileNotFoundException

This one puzzled - the file name in the Workflow.xml ‘CodeBesideAssembly’ was correct, and I thought the PublicKeyToken was okay too. Turned out that the ‘version’ was wrong - it seems to start at 3.0.0.0, but my assembly was only 1.0.0.0. Dunno why that was.

Getting the Public Key Token without copying things into the GAC

1) Create your Key pair, as per normal. Typically, this can be done as:
Sn.exe -k PublicPrivateKeyPair.snk
This will create a file containing both keys.

2) Extract the public key:
Sn.exe -p PublicPrivateKeyPair.snk PublicOnly.snk

3) Calculate the token. Note that the ‘-t’ parameter MUST be lower case (’-T’ does something different)
Sn.exe -t 'PublicOnly.snk'
And there you have the public key token

Update Infopath forms from within Workflow

So, I had been asked to write some code to update an Infopath form’s data as it passed through a workflow. This data was being declared as a column in SharePoint, and we wanted the columns value to update. A long struggle ensued… Read more »