Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Need help on filtering contents of Lookup using dynamic values of logged in user teams

(0) ShareShare
ReportReport
Posted on by

Need help on filtering contents of Lookup using dynamic values of logged in user teams. 

I am getting user team ids(and user team names) of logged in user. 

On the basis of this data I need to filter lookup field named UserTeam. 

Each logged in user should see only teams that it belongs to in UserTeam lookup field dropdown. 

Please help.

*This post is locked for comments

  • Shahbaaz Ansari Profile Picture
    6,211 on at
    RE: Need help on filtering contents of Lookup using dynamic values of logged in user teams

    did your issue got resolved?

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at
    RE: Need help on filtering contents of Lookup using dynamic values of logged in user teams

    Try out below code

    ************************************************

    function preFilterLookup() {  

    Xrm.Page.getControl("userteamid").addPreSearch(function () {

       addLookupFilter();

     });

    }

    function addLookupFilter() {

    var utms = getUserTeam();

    console.log("utms : "+ utms);

    var appender = "";

    for(var i=0; i < utms.length;i++){

    appender+="<value>"+utms[i]+"</value>";

    }

    console.log("appender : " + appender);

    var fetchXml =

     "<filter type='or'>" +

           "<condition attribute='teamid' operator='in'>" + appender + "</condition>" +

     "</filter>";

     Xrm.Page.getControl('userteamid').addCustomFilter(filterXml);

    }

    ************************************************

    Best Regards,

    Shahbaaz

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Need help on filtering contents of Lookup using dynamic values of logged in user teams

    Hi ,

    You can not combine user or team together as attributes search, so either you will search team or User.

    Here is the sample -

    For team search you should use "teamid"

       <condition attribute="teamid" operator="in">
            <value>{F5D59B17-5552-E711-8103-000C29CBC14A}</value>
            <value>{5BF1CF4A-5552-E711-8103-000C29CBC14A}</value>
            <value >{0708C620-5F52-E711-8103-000C29CBC14A}</value>
      </condition>


    For user search you should use"systemuserid"

          <condition attribute="systemuserid" operator="in">
            <value>{3374E2E2-0984-E711-8103-000C29CBC14A}</value>
            <value>{0F213284-AFDB-E711-8107-000C29CBC14A}</value>
            <value>{64675A4F-5973-E611-80E3-0050560111FF}</value>
          </condition>
  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at
    RE: Need help on filtering contents of Lookup using dynamic values of logged in user teams

    It should be just 'teamid'

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at
    RE: Need help on filtering contents of Lookup using dynamic values of logged in user teams

    ' entity doesn't contain attribute with Name = 'userteamid'.Detail:

    Make sure u r passing correct schema name...

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Need help on filtering contents of Lookup using dynamic values of logged in user teams

    Hi ,

    There is some extra ""  in the GUID.

    <filter type='or'>
        <condition attribute='userteamid' operator='in'>
            <value>"{8fb0f1ce-b94b-e711-80be-000c29f1ce86}"</value>
            <value>"{a67ff0c2-2d65-e711-80bf-000c29f1ce86}"</value>
            <value>"{5eec988c-4065-e711-80bf-000c29f1ce86}"</value>
            <value>"{547a6d5d-6427-e811-80c5-000c29f1ce86}"</value>
            </condition>
    </filter>

    Try to remove extra "" like below -

    <filter type='or'>
        <condition attribute='userteamid' operator='in'>
            <value>{8fb0f1ce-b94b-e711-80be-000c29f1ce86}</value>
            <value>{a67ff0c2-2d65-e711-80bf-000c29f1ce86}</value>
            <value>{5eec988c-4065-e711-80bf-000c29f1ce86}</value>
            <value>{547a6d5d-6427-e811-80c5-000c29f1ce86}</value>
            </condition>
    </filter>


    Hope this helps.

  • Community Member Profile Picture
    on at
    RE: Need help on filtering contents of Lookup using dynamic values of logged in user teams

    tried the above, still getting the exception as extracted from log file.

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: 'Team' entity doesn't contain attribute with Name = 'userteamid'.Detail:

    <OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance&quot; xmlns="schemas.microsoft.com/.../Contracts&quot;>

     <ActivityId>2c376489-9748-4b77-8817-a67841f4c4ab</ActivityId>

     <ErrorCode>-2147217149</ErrorCode>

     <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic&quot;>

       <KeyValuePairOfstringanyType>

         <d2p1:key>CallStack</d2p1:key>

         <d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema&quot; i:type="d4p1:string">   at Microsoft.Crm.Metadata.EntityMetadata.GetAttribute(String attributeName, NameMappingType mapping)

      at Microsoft.Crm.Query.DeserializeFetchVisitor.Visit(ConditionExpression condition)

      at Microsoft.Crm.Query.DeserializeFetchVisitor.Visit(FilterExpression criteria)

      at Microsoft.Crm.Query.DeserializeFetchVisitor.Visit(EntityExpression entity)

      at Microsoft.Crm.Query.EntityExpression.InternalDeserializeFromFetchXml(String xmlInfo, ParsingConditionValuesOption parsingOption, Boolean skipMissingAttributes)

      at Microsoft.Crm.Query.EntityExpression.InternalFromFetch(String fetchXml, DynamicMetadataCache dynamicCache, IUserAndOrganizationContext userAndOrganizationContext, ParsingConditionValuesOption parsingOption, Boolean skipMissingAttributes)

      at Microsoft.Crm.Application.Controls.LookupGridDataProvider.AddCustomFilter(QueryBuilder queryBuilder, String[] customFilters, String[] customFilterTypes)

      at Microsoft.Crm.Application.Controls.LookupGridDataProvider.SetupQueryBuilder(QueryBuilder qb, View view)

      at Microsoft.Crm.Application.Platform.Grid.GridDataProviderQueryBuilder.LoadQueryData()

      at Microsoft.Crm.Application.Platform.Grid.GridDataProviderQueryBuilder.LoadData()

      at Microsoft.Crm.Core.Application.WebServices.LookupService.ResolveLookupItem(Int32[] typesArray, String bindingColumns, String additionalParameters, String value, Int32 position, Boolean resolveEmailAddress, String savedQueryTypeParameter, View defaultView, String[] values, Boolean sortResults)

      at Microsoft.Crm.Core.Application.WebServices.LookupService.RetrieveItem(Int32[] typesArray, String bindingColumns, String additionalParameters, String[] values, Int32[] positions, Boolean resolveEmailAddress, String savedQueryTypeParameter, String defaultViewId, Nullable`1 defaultViewType, String defaultViewFetchXml, String defaultViewLayoutXml, String[] guidValues, Boolean sortResults)</d2p1:value>

       </KeyValuePairOfstringanyType>

     </ErrorDetails>

     <Message>'Team' entity doesn't contain attribute with Name = 'userteamid'.</Message>

     <Timestamp>2018-03-22T05:17:30.3169819Z</Timestamp>

     <ExceptionSource i:nil="true" />

     <InnerFault i:nil="true" />

     <OriginalException i:nil="true" />

     <TraceText i:nil="true" />

    </OrganizationServiceFault>

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at
    RE: Need help on filtering contents of Lookup using dynamic values of logged in user teams

    <value>'8fb0f1ce-b94b-e711-80be-000c29f1ce86'</value>

    You need to pass like above, remove the brackets {}

  • Community Member Profile Picture
    on at
    RE: Need help on filtering contents of Lookup using dynamic values of logged in user teams

    After trying above code, my appender and fetchXML are as follows.

    appender : <value>"{8fb0f1ce-b94b-e711-80be-000c29f1ce86}"</value><value>"{a67ff0c2-2d65-e711-80bf-000c29f1ce86}"</value><value>"{5eec988c-4065-e711-80bf-000c29f1ce86}"</value><value>"{547a6d5d-6427-e811-80c5-000c29f1ce86}"</value>

    fetchXml : <filter type='or'><condition attribute='userteamid' operator='in'><value>"{8fb0f1ce-b94b-e711-80be-000c29f1ce86}"</value><value>"{a67ff0c2-2d65-e711-80bf-000c29f1ce86}"</value><value>"{5eec988c-4065-e711-80bf-000c29f1ce86}"</value><value>"{547a6d5d-6427-e811-80c5-000c29f1ce86}"</value></condition></filter>

    Can you suggest what could be wrong here?

  • Community Member Profile Picture
    on at
    RE: Need help on filtering contents of Lookup using dynamic values of logged in user teams

    H?!
     
    It seems like you have to create additional system view for team entity and set it to teams lookup field on your form.
    Here is an example:
     
    47527.Screenshot_5F00_1.png

    Hope it helps

    Please mark it As Answered or Verified if it did help you.

    Thanks

    Vlad
    dynamicalabs.com

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans