At its core, the EqualUserId condition operator in FetchXML allows you to fetch records where a particular user lookup field matches the ID of the user executing the FetchXML query. This becomes invaluable when you want to retrieve records specific to the user running the query, such as tasks assigned to them, leads they’re handling, or opportunities they’re overseeing.
Practical Application of EqualUserId
a. Fetching Assigned Tasks:
Suppose you’re building a dashboard that dynamically lists tasks assigned to the currently logged-in user. Using the EqualUserId operator, the FetchXML query might look something like this:
<fetch>
<entity name="task">
<attribute name="subject" />
<attribute name="scheduledend" />
<filter>
<condition attribute="ownerid" operator="eq-userid" />
</filter>
</entity>
</fetch>
b. Retrieving Leads Managed by the Current User:
To fetch leads managed by the currently logged-in user:
<fetch>
<entity name="lead">
<attribute name="fullname" />
<attribute name="emailaddress1" />
<filter>
<condition attribute="ownerid" operator="eq-userid" />
</filter>
</entity>
</fetch>
