web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Custom view issue while populating value in Javascrip

(0) ShareShare
ReportReport
Posted on by 167

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();

},

I have the same question (0)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 74 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans