XPath filter for EnumerateResourcesActivity
Can we use variables in the XPath filter? In my enumerateResourcesActivity I am using this.enumerateResourcesActivity1.XPathFilter = "/Person"; which gives me all the user. I want to use this in a custom workflow where I want to get only the current requests person object. (In other words: If the users Manager or phone number changes I want to invoke this custom workflow and act only on that user) how do I get the only the current person being modified instead of everyone. I tried few things like: "/Request/ObjectID" "/Target/ObjectID" but these did not work. Any guidance will help Thanks, Krish
June 21st, 2010 7:34pm

Hi Krish! First of all I recommend you to use the ReadResourceActivity if you're only fetching a single resource that you know the ResourceID for. To get the ResourceID for the target resource from the workflow do like this: First get the current workflow like this: // Try to get parent workflow.<br/> SequentialWorkflow containingWorkflow = null;<br/> if (!SequentialWorkflow.TryGetContainingWorkflow(this, out containingWorkflow))<br/> {<br/> throw new InvalidOperationException("Could not get parent workflow!");<br/> } Then you should be able to get the target resource for the request like this: Guid targetID = containingWorkflow.TargetID; If you instead of an enumerateResourcesActivity use a ReadResourceActivity you set it's ResourceID property for the resource you wish to get and some extra attributes like this: this.readResourceActivity1.ResourceId = targetID;<br/> this.readResourceActivity1.SelectionAttributes = new string[]{"City",Company","Manager"} Then when the activity has been executed you could get your resource like this: ResourceType person = readResourceActivity1.Resource; ...But to answer your question, Yes - you can use variables in the XPath expresssions and here's a way to do it: this.enumerateResourcesActivity1.XPathFilter = "/Person[ObjectID='" + targetID.ToString() + "']"; ...Or like this if you want the manager for the person: this.enumerateResourcesActivity1.XPathFilter = "/Person[ObjectID='" + targetID.ToString() + "']/Manager"; ...Or rather like the persons this person manages: this.enumerateResourcesActivity1.XPathFilter = "/Person[Manager='" + targetID.ToString() + "']"; By using the containingWorkflow you don't have to use the CurrentRequestActivity for just getting the TargetID. I recommend you to have a look at the FIM XPath reference that can be found here: http://msdn.microsoft.com/en-us/library/ee652287.aspx //Henrik Henrik Nilsson, ILM/FIM MVP Blog: http://www.idmcrisis.com Company: Cortego (http://www.cortego.se)
Free Windows Admin Tool Kit Click here and download it now
June 21st, 2010 8:30pm

Hi, I am trying to use the ReadResourceActivity and having some problems following the example. I think perhaps I am misunderstanding where the code needs to execute since I am new to WF. The line: ResourceType person = readResourceActivity1.Resource; always returns null. I have created a Sequence Activity that contains a CodeActivity-->readResourceActivity-->UpdateResourceActivity. (My goal is to modify a group's display name based on the owner of the group. The updateResourceActivity does not return the owner when the group is edited, so I'm trying to use readResourceActivity1 to get that.) I tried putting the readResourceActivity before the CodeActivity, but that fails with "Invalid requestor specified for Get Operation". Here is my code if anyone can see where I have gone wrong, I would really appreciate it. I've not had much luck finding documentation on the ReadResourceActivity. ReadOnlyCollection<CreateRequestParameter> requestParameters = this.currentRequest.ParseParameters<CreateRequestParameter>(); TargetId = currentRequest.Target.GetGuid(); SequentialWorkflow containingWorkflow = null; if (!SequentialWorkflow.TryGetContainingWorkflow(this, out containingWorkflow)) { throw new InvalidOperationException("Could not get parent workflow!"); } Guid wfTargetId = containingWorkflow.TargetId; this.readResourceActivity1.ResourceId = wfTargetId; //I've checked and this does return the GUID I expect it to. this.readResourceActivity1.SelectionAttributes = new string[] { "Owner" }; ResourceType resource = readResourceActivity1.Resource; this.SimpleLogFunction("Got person.", "", EventLogEntryType.Information, 10002, 100); if (resource != null) { //haven't gotten to here, but need to grab the value of the owner attribute. } else { this.SimpleLogFunction("resource is null", "", EventLogEntryType.Information, 10002, 100); } Thank you for any guidance or help! Sami
July 11th, 2010 5:27pm

Hi Sami! If all this code exists within the same event handler it's not strange at all readResourceActivity1.Resource returns null since the activity is initialized in the same method and the ReadResourceActivity never gets to be executed before you try to read the found resource. If you add a code activity after your ReadResourceActivity that handles the code from the "ResourceType resource = readResourceActivity1.Resource;" line you'll see that it works better. //HenrikHenrik Nilsson, ILM/FIM MVP Blog: http://www.idmcrisis.com Company: Cortego (http://www.cortego.se)
Free Windows Admin Tool Kit Click here and download it now
July 13th, 2010 11:12am

Thank you, Henrik. I appreciate it!
July 30th, 2010 5:25pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics