Tuesday, March 3, 2009

Caution binding multi-valued activity properties

Someone ran into this problem while following my blog post on account name generation, so I thought I'd detail the steps of the pitfall. Here's the scenario: you followed all the steps for the custom workflow activity to generate an account name, but the account name doesn't update at all after testing the activity in an ILM 2 workflow. Well, you may have incorrectly bound the multi-valued UpdateParameters property on the UpdateResourceActivity. It's an easy mistake to make, as I'll show you.

Okay, let's trace our steps. You've just dragged a new UpdateResourceActivity onto your custom workflow.

Now, you want to bind the (single-valued) ResourceId property to a new field. In the Properties window in Visual Studio, you click on the ResourceId property, and then click on the elipsis button.

Now you see a dialog in which you choose an existing field/property or create a new one. In my earlier blog post, I instructed you to create a new field named "TargetId".

So far, so good. Next, you want to bind the (multi-valued) UpdateParameters property to a new field. You click on the UpdateParameters property and click on the elipsis again.

Wait, what's this? You don't see the same dialog that you saw for the single-valued property.

How do you bind the property in the same way you did with the single-valued property with this dialog? The answer is: you don't. If you were to attempt to do the same by clicking the Add button, what you're actually doing is assigning the UpdateParameters in the designer-generated code, which isn't where we want to do it. We want to assign the UpdateParameters from our code activity.

Cancel out of the dialog and, instead of clicking on the elipsis, click on the "Bind Property..." link below.

Now you see the appropriate dialog, and you can create a new field named "MyUpdateParameters" to which you'll bind this property.

Sometimes Visual Studio will disable the "Bind Property..." link when it's not supposed to. This can make things especially confusing. I was able to get Visual Studio to re-enable the link with the following steps:
  1. Click on the elipsis for the multi-valued property.
  2. In the Collection Editor dialog, click Add and then Remove.
  3. Click OK to close the dialog.
One final note: you actually don't have to bind the UpdateParameters property. You can assign it directly from the UpdateResourceActivity object:

//--- Add the account name to the update parameters.
updateResourceActivity1.UpdateParameters = new UpdateRequestParameter[]
new UpdateRequestParameter("AccountName",
UpdateMode.Modify, accountName)

1 comment:

  1. Incredible article distributed here by you. I have long been eager to adapt new things in relation to this topic, and there is no doubt that I have adapted new things today.Hotel Broker in Kansas