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