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
did your issue got resolved?
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
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>
It should be just 'teamid'
' entity doesn't contain attribute with Name = 'userteamid'.Detail:
Make sure u r passing correct schema name...
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.
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" xmlns="schemas.microsoft.com/.../Contracts">
<ActivityId>2c376489-9748-4b77-8817-a67841f4c4ab</ActivityId>
<ErrorCode>-2147217149</ErrorCode>
<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic">
<KeyValuePairOfstringanyType>
<d2p1:key>CallStack</d2p1:key>
<d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" 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>
<value>'8fb0f1ce-b94b-e711-80be-000c29f1ce86'</value>
You need to pass like above, remove the brackets {}
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?
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:
Hope it helps
Please mark it As Answered or Verified if it did help you.
Thanks
Vlad
dynamicalabs.com
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
54
Victor Onyebuchi
6