{SCIRPTING TIP} Filter Lookup field based on ownership in Dynamics CRM

User Review
0 (0 votes)

Requirement: To filter a Lookup field options dependent on the record ownership for Lookup entity as the current user or his/her teams.


Description: The lookup field should be filtered based on lookup entities record owned by the current user or his/her teams.


This was achieved by adding Pre-filter to the lookup field as below:

function preFilterLookup()


      Xrm.Page.getControl(“lookupfieldname”).addPreSearch(function ()


// Filter the fetchxml ownership

fetchXml = “<filter type=’and’><condition attribute=’ownerid’ operator=’eq-useroruserteams’/></filter>”;

// Apply the filter to the field




Note: Applies to CRM 2013 and up.

Hope it helps and Happy CRMing!