Skip to content

Getting something back from the EnumerateResourcesActivity

I have just spent a very frustrating day trying to figure out how to get access to the resource found by the EnumerateResourcesActivity, not helped even slightly by the usual machine-generated “documentation“. I’m still not very happy with it, and can’t for the life of me understand why it can’t give me a straight object collection as output, but at least I’ve got the data I need from it now.

The EnumerateResourcesActivity is the recommended way to search for objects using an XPath filter. But, quite bizarrely, the only readily accessible data you get back from it is how many objects it found – not the actual objects! This is despite the fact that one of the input parameters is a list of attributes you want back. I feel cheated!!

The only time I’d used this activity before was for checking uniqueness, and all I needed then was an object count. But today I needed to write a custom Notification Activity and (as there’s no way I know of to add an Identity Picker to a custom workflow UI) I wanted to be able to specify the email template by it’s name.

Clearly this was going to involve an object lookup as I need to specify the template’s ResourceID going in to the EmailNotificationActivity. In this example the “searchEmailTemplate” activity is the EnumerateResourcesActivity, and I only expect it to return one object.

This is where all the pain started, and if it hadn’t been for the following blog posts I never would have worked this out:

http://c–shark.blogspot.com.au/2009/04/how-to-use-enumerateresourcesactivity.html#comment-form (including comments as it was Luka who had the crucial bit of advice that you need to set all the properties on the EnumerateResourcesActivity going in).
http://bennettadelson.wordpress.com/2012/02/20/fim-2010-user-rcdc-to-add-user-to-groups/
http://blog.clauskonrad.net/2011/11/fim-2010-how-to-use-std.html
http://www.fimspecialist.com/fim-portal/custom-workflow-examples/custom-workflow-example-enumerate-resources-activity/

So thank you very much lovely bloggers for sharing your experiences on this!

The Code

The first totally weird thing you have to do is hack the Designer code for your custom workflow. I’m using VB.NET so mine is called <ActivityName>.Designer.vb. I found I had to click “Show All Files” to see it:

We have to completely ignore the message that says we shouldn’t edit this code and do the following:

  • Add a declaration for codeActivity1 at the end of the class, and
  • Add the lines as shown before “Me.CanModifyActivities = False” inside the InitializeComponent Sub.
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class AlternateEmailNotification

    'NOTE: The following procedure is required by the Workflow Designer
    'It can be modified using the Workflow Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerNonUserCode()> _
    <System.CodeDom.Compiler.GeneratedCode("", "")> _
    Private Sub InitializeComponent()
	   ... (pre-existing code) ...
        '
        ' Manually added code for the EnumerateResourcesActivity
        '
        Me.codeActivity1 = New System.Workflow.Activities.CodeActivity()
        Me.codeActivity1.Name = "codeActivity1"
        AddHandler Me.codeActivity1.ExecuteCode, AddressOf Me.GetEmailTemplate_ExecuteCode
        'Make the codeActivity the child of the EnumerateResourcesActivity 
        Me.searchEmailTemplate.Activities.Add(Me.codeActivity1)

        Me.CanModifyActivities = False
    End Sub

    ... (pre-existing declarations) ...

    'Manually added code activity that allows access to objects returned by EnumerateResourcesActivity
    Private codeActivity1 As CodeActivity
End Class

In the code for the activity itself (AlternateEmailNotification.vb in the picture above) I add the following code which is being called by that handler we added above. This does actually manage to get you the first object returned by the enumeration. (I still don’t know how to get at all the objects found but don’t need to for this activity – leaving that for another day.)

    Private Sub GetEmailTemplate_ExecuteCode(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim currentItem As ResourceType = TryCast(EnumerateResourcesActivity.GetCurrentIterationItem(DirectCast(sender, CodeActivity)), ResourceType)
        If currentItem Is Nothing Then
            Throw New WorkflowTerminatedException("Unable to find email template " & Me.Template)
        End If
        'TemplateID is a System.Guid declared globally
        TemplateID = currentItem.ObjectID.GetGuid
    End Sub

Now back on more familiar ground, here’s the code activity that runs just before the EnumerateResourcesActivity to set the scene. Remember as I’ve mentioned you have to set all the properties. If you don’t you wind up with “Nothing” instead of a resource.

    Private Sub initSearch_ExecuteCode(ByVal sender As System.Object, ByVal e As System.EventArgs)
        searchEmailTemplate_ActorId1 = New Guid(FIMADMIN_GUID)
        Dim filter As String = "/EmailTemplate[DisplayName ='" & Me.Template & "']"
        searchEmailTemplate_XPathFilter1 = filter
        searchEmailTemplate_Selection1 = New String() {"DisplayName"}
        searchEmailTemplate_PageSize1 = 100
        searchEmailTemplate_SortingAttributes1 = Nothing
        searchEmailTemplate_TotalResultsCount1 = 0
    End Sub

Finally now I set up my EmailNotificationActivity, which was at least as simple as advertised.

    Private Sub initNotification_ExecuteCode(ByVal sender As System.Object, ByVal e As System.EventArgs)
        emailNotificationActivity_To1 = EmailOther
        emailNotificationActivity_EmailTemplate1 = TemplateID
    End Sub

{ 2 } Comments

  1. Mark | June 17, 2014 at 4:27 pm | Permalink

    Hi Carol – thank you for the awesomely clear write-up for this issue. It’s been sending me nuts for days, and your explanation and solution got me working. Much appreciated.

  2. Carol | June 17, 2014 at 10:41 pm | Permalink

    That’s an obscure one isn’t it. Glad I could help!

Post a Comment

Your email is never published nor shared. Required fields are marked *

Spam comments will be blocked by Akismet

*

Endep online order order buy Endep online purchase Endep online without script buy generic Endep from india buy in Endep uk where to buy Endep without a prescription Endep from canada buy 10 mg Aricept generic Aricept cost order Nizoral no visa Nizoral 200 mg buy cheap Nizoral line Nizoral on line best finpecia online pill Requip Requip free Requip uk Amitriptyline generic buy generic Amitriptyline from india where buy Lisinopril purchasing finpecia with overnight delivery Nizoral online buy saturday delivery buy Nizoral in mo how to buy Cytotec online without a rx order Aricept pharmacy buy Aricept with no prescription buy Amitriptyline no perscription cod Online us Requip how to buy Amitriptyline without a prescription buy line Amitriptyline buy Amitriptyline money buy purchase Accutane 40 mg on line no rx Accutane 40 mg sale order 40 mg Accutane online next day delivery 40 mg Accutane online buy Lisinopril pay cod Lisinopril overnight cod buy lisinopril without prescription buy lisinopril purchase Premarin cod next day delivery where buy Premarin buy Premarin online free fedex delivery Premarin no rx Metformin buy Metformin canada cheapest place to buy Metformin purchase Metformin online generic 20mg prednisone online finpecia online overnight buy generic Finpecia uk online|Finpecia 1 mg order online|Finpecia generic vs propecia|Finpecia cost australia|buy generic Finpecia uk|purchase Finpecia uk|buy Finpecia online prescription|buy generic Finpecia 1mg|buy Finpecia|Finpecia online australia|buy Finpecia no prescription uk|order Finpecia 1mg|buy Finpecia cheap|Finpecia generic 1mg|Finpecia online prescription|Finpecia 1mg generic canada|Finpecia costco pharmacy|Finpecia 1mg india|Finpecia generic walmart|buy Finpecia no prescription forum|buy Finpecia online australia|Finpecia online uk) buy finpecia cheap legal buy Finpecia online online|buy cheap Finpecia online|order Finpecia|Finpecia generic walmart|Finpecia online prescription|buy Finpecia 1mg online|Finpecia generic online|Finpecia costco price|order Finpecia online|buy Finpecia 1mg malaysia|purchase Finpecia uk|topical Finpecia buy|Finpecia 1 mg order online|Finpecia generic|buy Finpecia online canada|Finpecia 1 mg order online|Finpecia online india|Finpecia generic 1 mg|order Finpecia uk|Finpecia depression women|buy cheap Finpecia 1mg|Finpecia generic names|legal buy Finpecia online|Finpecia depression women|buy Finpecia 1mg india|Finpecia generic walmart|buy Finpecia 1mg online|Finpecia online india|buy Finpecia 1mg online|Finpecia 1mg tablets|Finpecia costco price|order Finpecia canada|buy Finpecia online australia|Finpecia dose hair|buy Finpecia online paypal|Finpecia 1mg|Finpecia 1mg for sale|Finpecia online uk|buy Finpecia uk|Finpecia 1mg vs 1mg|Finpecia generic walmart|Finpecia costco pharmacy|buy Finpecia on buy Metformin toronto uk order Metformin Metformin online Metformin prescription buy Metformin where order finpecia canada buy finpecia order Metformin usa online Orlistat buy buy in Orlistat uk buy prednisone topix buy prednisone youtube Orlistat toronto buy discount Orlistat line buy cheap Orlistat without prescription prednisone prescription cost Metformin order online pharmacy Metformin how to buy Metformin without a prescription Metformin price lisinopril buy lisinopril