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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

RetrieveMultiple in fetchxml and use result in a custom view

(0) ShareShare
ReportReport
Posted on by

I try to use the javascript below to set up a custom view, but this doesn't work yet. In the console I neatly see my results from my FetchXML but not in custom view. Could someone help me with this?

function SetApproverLookup(executionContext) {
var formContext = executionContext.getFormContext();
if (formContext.getAttribute("xx_profit").getValue() != null) {

//get
var profit = formContext.getAttribute("xx_profit").getValue();
var profitcenterid = profit[0].id;
var profitcentername = profit[0].name;

//build fetchxml
var viewId = "d9624884-d975-4367-bc10-cfb2e3aaab01";
var entityName = "systemuser";
var viewDisplayName = "Approvers " + profitcentername;

var FetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='systemuser'>"+
"<attribute name='fullname' />"+
"<attribute name='systemuserid' />"+
"<link-entity name='connection' from='record2id' to='systemuserid' alias='ab'>" +
"<filter type='and'>" +
"<condition attribute='record1id' operator='eq' value='" + profitcenterid + "' />" +
"<condition attribute='record2roleid' operator='eq' value='70F64E53-B6A3-E911-A9A4-000D3AB6E6B1' />" +
"</filter>" +
"</link-entity>" +
"</entity>"+
"</fetch>";

//build grid layout
var layoutXml = "<grid name='resultset' " +
"object='1' " +
"jump='fullname' " +
"select='1' " +
"icon='1' " +
"preview='1'>" +
"<row name='result' " +
"id='systemuserid'>" +
"<cell name='fullname' " +
"width='300' />" +
"</row>" +
"</grid>";

FetchXML = "?fetchXml=" + encodeURIComponent(FetchXML);
Xrm.WebApi.retrieveMultipleRecords("systemuser", FetchXML).then(
function success(result) {
for(var i=0; i < result.entities.length; i++) {
console.log(result.entities[i]);

}
//add new view
formContext.getControl("xx_approver").addCustomView(viewId, entityName, viewDisplayName, FetchXML, layoutXml, true);

},
function (error) {
console.log(error.message);
}
)
}
}

*This post is locked for comments

I have the same question (0)
  • Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans