Hi All ,
I have requirement where to get multiple value of country and populate in country look field and i fetched the value also from multiple record of teams of user and store in array with id,entity and country name
This data extraction is not possible from fetchxml, so i fetched it through iteration as every team has different country so it collected all country from all teams a user belongs to in var lookup as shown in below code .
I'm trying to populate these all country name in custom view, but i'm getting error 'Xml passed to platform in invalid' ,
Please help, if its possible to populate custom view from lookup array, i need to populate on countryname in custom view .
Code is below
filterCountryLookup: function(formContext) {
var userID = Xrm.Utility.getGlobalContext().userSettings.userId;
var userName = Xrm.Utility.getGlobalContext().userSettings.userName;
var viewId = "{FCEF151C-F1A9-E811-8142-3863UB357WA0}";
var viewDisplayName = "Country View";
var entityName="asc_country";
var lookup=new Array();
var fetchXmlQuery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
" <entity name='team'>" +
" <attribute name='teamid' />" +
" <attribute name='teamtype' />" +
" <attribute name='asc_country' />" +
" <order attribute='asc_country' descending='false' />" +
" <link-entity name='teammembership' from='teamid' to='teamid' visible='false' intersect='true'>" +
" <link-entity name='systemuser' from='systemuserid' to='systemuserid' alias='ad'>" +
" <filter type='and'>" +
" <condition attribute='systemuserid' operator='eq' uiname='" + userName + "' uitype='systemuser' value='" + userID + "' />" +
" </filter>" +
" </link-entity>" +
" </link-entity>" +
" </entity>" +
"</fetch>";
var encodedfetchxml = encodeURIComponent(fetchXmlQuery);
var req = new XMLHttpRequest();
req.open(
"GET",
Xrm.Page.context.getClientUrl() +
"/api/data/v9.1/teams?fetchXml=" +
encodeURIComponent(fetchXmlQuery),
true
);
req.setRequestHeader("Prefer", 'odata.include-annotations="*"');
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
for(var i=0;i<results.value.length;i++)
{
var country=results.value[i]["_asc_country_value@OData.Community.Display.V1.FormattedValue"];
var countryid=results.value[i]._asc_country_value;
var entityname=results.value[i]["_asc_country_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
lookup[i]=new Object();
lookup[i].id=countryid;
lookup[i].name=country;
lookup[i].entityType=entityname;
}
var layoutXml = "<grid name='resultset' object='2' jump='name' select='1' icon='1' preview='1'>" +
"<row name='result' id='id'>" +
"<cell name='country' width='300' />" +
"</row>" +
"</grid>";
if (lookup!== undefined) {
formContext.getControl("asc_countryid").addCustomView(viewId, entityName, viewDisplayName, lookup, layoutXml, true);
formContext.getControl("asc_countryid").setDefaultView(viewId);
}
console.dir(results);
} else {
alert(this.statusText);
}
}
};
req.send();
},