Wednesday, September 1, 2010

FetchXml and the current user

I'm adding this because I can never remember how to do this...  Every once in a while I have to execute a fetchXml statement that has to use the current userId as part of the filter.  Here's how you do it:

<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
    <entity name='neu_lastopenedobject'>
        <attribute name='neu_contactid'/>
        <attribute name='neu_lastopenedobjectid'/>
        <filter type='and'>
            <condition attribute='ownerid' operator='eq-userid'/>

Note the 'condition' node.  We're able to filter against the current user by using the operator='eq-userid' attribute.  Microsoft has all of this documented somewhere...