Thursday, June 4, 2009

Create a set with all objects having a non-empty attribute (i.e. XPath filter for 'child exists')

Today I answered a question on the FIM forums, and I thought I'd publish it for reference.

Objective
How can we create a Set of objects whose certain attribute is not blank (meaning that the attribute exists)? For example, how do we create a Set of all people who have a JobTitle assigned? The FilterBuilder won't let you do something like Job Title is not        .

Solution
The answer is that we have to edit the Set's XPath filter manually.

But first, a quick note on semantics. :) In FIM we talk about objects and their attributes, but 'attribute' is something different in XML (which is what XPath is operating on). So, the objective for our XPath query is to find all nodes whose child node (of a certain name) is not blank.

  1. We can begin by using the filter builder as a crutch. Create the following filter with the filter builder:

    Select people that match all of the following conditions:
    Job Title is not junk

    If you view membership, it will give you all people who don't have a job title; and the filter will be:

    /Person[not(JobTitle = 'junk')]

  2. Finish & submit the Set creation.

  3. Go back and edit the Set; Click on Advanced View, and change the filter manually to:

    /Person[JobTitle != 'junk']

  4. Finish and submit the changes.

Now, if you do an XPath query for /Set[DisplayName = 'Those with job title']/ComputedMember, you'll see all people who do have a job title (provided you don't actually have a job title named 'junk').

2 comments:

  1. Thanks CShark! I've been banging my head against a brick wall on this one. Many of the approaches I took with manually editing Xpath query under the advanced view seemed to bork with request failed (it didn't like the syntax or similar). This approach seems to work nicely and simply :)

    ReplyDelete
  2. I wish you could learn smm with me, I have a lot of useful tips and hacks to this topics. But currently I struggle with my blogging.

    ReplyDelete