Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

RetrieveMultiple in fetchxml and use result in a custom view

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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

  • Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 User Group Leader on at
    RE: RetrieveMultiple in fetchxml and use result in a custom view

    Hey TonHaz,

    Please try below link:

    https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/123587/addcustomview-and-setdefaultview-not-working-correctly

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans