14 November, 2011

FIM 2010: How to read values using native FIM WF objects.

When using the “native” FIM workflow activities for FIM 2010 interaction, it is not always intuitive how to actually retrieve the values from the objects in FIM. In this example, we will be reading properties from a Person-object.

1) Start by creating a new WorkflowActivity [std. WF 3.5]

image_thumb1

2) Drag in the following Activities

2.1) CurrentRequestActivity [Microsoft.ResourceManagement]

2.2) CodeActivity [std. WF 3.5]

2.3) ReadResourceActivity [Microsoft.ResourceManagement]

2.4) CodeActivity [std. WF 3.5]

image

3) Bind the first Activity (fimCurrentRequest) to a newly created DependencyProperty (fimCurrentRequest_CurrentRequest). This will create an object in your workflow of the type: (Microsoft.ResourceManagement.WebServices.WSResourceManagement.RequestType)
This object you will be referring later in code.

image

4) Bind the second FIM Activity (fimReadResource) to a newly created DependencyProperty (fimReadResource_Resource). This property will hold the result (TargetObject) read by the activity (fimReadResource). A property we will be referring to later…

image

Now we are all set to implement the 2 code activities.

The first code activity will prepare the ReadResourceActivity that should read the TargetObject. This preparation consist of setting the ActorId as well as the ResourceId of the TargetObject. The code behind the first Code Activity is seen below:

private void prepareRead_ExecuteCode(object sender, EventArgs e)
{
//set actor
this.fimReadResource.ActorId = this.fimCurrentRequest_CurrentRequest.Creator.GetGuid();

//set resourceID
this.fimReadResource.ResourceId = this.fimCurrentRequest_CurrentRequest.Target.GetGuid();
}

Reading values from TargetObject (second CodeActivity)
When reading values from the targetobject, you need to know the system names of the attributes you are interested in as well as the data type. In this example, we will be looking for the value of “Cost Center”. As seen in the below screenshot, this attribute is of type Indexed String and the system name is CostCenter.


image


The last codeactivity – is using the below code snippet. As seen you can read explicit properties like ‘DisplayName’ etc, but also custom properties like Cost Center. As previously discussed you need to know the system Name as well as the data type to read this property.

Accessing properties on an object other than the immediate available, you get these like this:
<type> variable = <object>[<propertyName>]. Example see below for ‘CostCenter’.

private void writeOutResource_ExecuteCode(object sender, EventArgs e)
{
//read creator ID (of the TargetObject!)
Guid cId = this.fimReadResource_Resource.Creator.GetGuid();

//read displayName (of the TargetObject)
string disp = this.fimReadResource_Resource.DisplayName;

//read Manager of this person
Guid mgrId = (Guid)this.fimReadResource_Resource["Manager"];

//read name of Cost Center
string ccName = (string)this.fimReadResource_Resource["CostCenter"];

//Write out values...
Trace.WriteLine(string.Format("TargetID = {0}", cId.ToString()));
Trace.WriteLine(string.Format("DisplayName = {0}", disp));
Trace.WriteLine(string.Format("Manager (ID) = {0}", mgrId.ToString()));
Trace.WriteLine(string.Format("Cost Center = {0}", ccName));
}

Not all that intuitive I must admit!


StackOverflow Tags:

No comments:

InRiver: Not loading your extensions?

(You really need to in the loop to appreciate the issue this post addresses). Man, I've been fighting this problem for hours before I ...