Hi Folks,
I Have an requirement to fetch the parent business unit and under child business unit with team members by using PCF control or custom code .
I am trying using a PCF Control but this is not matching my requirement .
I have implemented a html web resource for custom tree view control but i am unable to fetch newly created Business Unit.
<html><head>
<script>
function setClientApiContext(xrm, formContext) {
window.Xrm = xrm;
alert("hello");
window._formContext = formContext;
getBusinessUnits_Hierarchy(formContext);
}
function getBusinessUnits_Hierarchy(formContext) {
//var context = GetGlobalContext();
var userRecordId = formContext.data.entity.getId();
var salesOrgId;
if (formContext.getAttribute("stp_salesorg").getValue() != null && formContext.getAttribute("stp_salesorg").getValue() != undefined) {
debugger;
salesOrgId = formContext.getAttribute("stp_salesorg").getValue();
if (salesOrgId != null && salesOrgId != "") {
salesOrgId = salesOrgId[0].id;
}
}
var fxml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
fxml += "<entity name='systemuser'>";
fxml += "<attribute name='fullname' />";
fxml += "<attribute name='positionid' />";
fxml += "<attribute name='systemuserid' />";
fxml += " <attribute name='parentsystemuserid' />";
fxml += "<attribute name='jobtitle' />";
fxml += " <order attribute='fullname' descending='false' />";
fxml += " <filter type='and'>";
fxml += " <condition attribute='isdisabled' operator='eq' value='0' />";
fxml += " </filter>";
fxml += " <link-entity name='stp_salesorg' from='stp_salesorgid' to='stp_salesorg' link-type='inner' alias='ai'>";
fxml += " <attribute name='stp_name' />";
fxml += " <attribute name='stp_manager' />";
fxml += " <attribute name='stp_parentsalesorgid' />";
fxml += " <attribute name='stp_parentsalesorgidname' />";
fxml += " <filter type='and'>";
fxml += " <filter type='or'>";
fxml += " <condition attribute='stp_parentsalesorgid' operator='eq' uiname='Qatar Sales' uitype='stp_salesorg' value='" + salesOrgId + "' />";
fxml += " <condition attribute='stp_salesorgid' operator='eq-or-under' uiname='Qatar Sales' uitype='stp_salesorg' value='" + salesOrgId + "' />";
fxml += " </filter>";
fxml += " </filter>";
fxml += " </link-entity>";
fxml += " </entity>";
fxml += "</fetch>";
fxml = "?fetchXml=" + encodeURIComponent(fxml);
parent.Xrm.WebApi.retrieveMultipleRecords("systemuser", fxml).then(
function success(result) {
console.log(result);
if (result!= null && result.entities.length > 0) {
var roles = "";
document.getElementById("myId").innerHTML = "";
// var span = '<span class="caret">'+ result.entities[1]["stp_name"]+'</span>';
var Dubairul = "";
var Dubaili = "";
var IndSalesul = "";
var IndSalesli = "";
var Puneul = "";
var Puneli = "";
var Qatarul = "";
var Qatarli = "";
var Puneul = "";
var Puneli = "";
var SalesOrgName;
var Dubaispan;
var Qatarspan;
var Indiaspan;
var Punespan ;
for (var rolecount = 0; rolecount < result.entities.length; rolecount++) {
SalesOrgName = result.entities[rolecount]["ai.stp_name"];
if (result.entities[rolecount]["ai.stp_name"] == SalesOrgName) {
//var DubaiPaerntspan = '<span class="caret">' + result.entities[rolecount]["ai.stp_parentsalesorgidname"] + '</span>';
Dubaispan = '<span class="caret">' + result.entities[rolecount]["ai.stp_name"] + '</span>';
if (result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] != undefined) {
Dubairul = '<ul class="caret"> <input type="checkbox"> ' + result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] + ' ';
}
// Qatarul = '<ul class="caret"> <input type="checkbox"> ' + result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] + ' ';
if (result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] != result.entities[rolecount].fullname) {
if (Dubaili = "") {
Dubaili = '<ul class="nested"><li><input type="checkbox">' + result.entities[rolecount].fullname + '</li>';
}
else {
Dubaili = Dubaili + '<li ><input type="checkbox">' + result.entities[rolecount].fullname + '</li>';
}
}
}
else if (result.entities[rolecount]["ai.stp_name"] == SalesOrgName) {
Qatarspan = '<span class="caret">' + result.entities[rolecount]["ai.stp_name"] + '</span>';
if (result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] != undefined) {
Qatarul = '<ul class="caret"> <input type="checkbox"> ' + result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] + ' ';
}
// Qatarul = '<ul class="caret"> <input type="checkbox"> ' + result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] + ' ';
if (result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] != result.entities[rolecount].fullname) {
if (Qatarli= "") {
Qatarli = '<ul class="nested"><li><input type="checkbox">' + result.entities[rolecount].fullname + '</li>';
// li = ' <ul class="nested"><li><input type="checkbox">' + result.entities[rolecount].fullname + '</li></ul >';
}
else {
Qatarli = Qatarli + '<li ><input type="checkbox">' + result.entities[rolecount].fullname + '</li>';
}
}
}
else if (result.entities[rolecount]["ai.stp_name"] == SalesOrgName) {
Indiaspan = '<span class="caret">' + result.entities[rolecount]["ai.stp_name"] + '</span>'; //5ac43ff6-4a80-ed11-81ad-000d3aba3d9c
if (result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] != undefined) {
IndSalesul = '<ul class="caret"> <input type="checkbox"> ' + result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] + ' ';
}
//IndSalesul = '<ul class="caret"> <input type="checkbox"> ' + result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] + ' ';
if (result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] != result.entities[rolecount].fullname) {
if (IndSalesli= "") {
IndSalesli = '<ul class="nested"><li><input type="checkbox">' + result.entities[rolecount].fullname + '</li>';
}
else {
IndSalesli = IndSalesli + '<li ><input type="checkbox">' + result.entities[rolecount].fullname + '</li>';
}
}
}
else if (result.entities[rolecount]["ai.stp_name"] == SalesOrgName) {
Punespan = '<span class="caret">' + result.entities[rolecount]["ai.stp_name"] + '</span>';
if (result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] != undefined) {
Puneul = '<ul class="caret"> <input type="checkbox"> ' + result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] + ' ';
}
if (result.entities[rolecount]["ai.stp_manager@OData.Community.Display.V1.FormattedValue"] != result.entities[rolecount].fullname) {
if (Puneli = "") {
Puneli = '<ul class="nested"><li><input type="checkbox">' + result.entities[rolecount].fullname + '</li>';
// li = ' <ul class="nested"><li><input type="checkbox">' + result.entities[rolecount].fullname + '</li></ul >';
}
else {
Puneli = Puneli + '<li ><input type="checkbox">' + result.entities[rolecount].fullname + '</li>';
//IndSalesli = IndSalesli + '+<br>' + Punespan + Puneul + Puneli;
IndSalesli = IndSalesli + '+<br>'+ Puneul + Puneli;
//var PuneDiv="<div id="myId1"><ul id="myUL"><li> ' + Punespan + ' ' + Puneul + ' ' + Puneli + '</ul></li></ul></div>";
}
}
}
// document.getElementById("myId").innerHTML += '<body><div id="myId1"><ul id="myUL"><li>' + Dubaispan + ' ' + Dubairul + ' ' + Dubaili + '</ul></li></ul></div><div id="myId1"><ul id="myUL"><li> ' + Qatarspan + ' ' + Qatarul + ' ' + Qatarli + '</ul></li></ul></div><div id="myId1"><ul id="myUL"><li> ' + Indiaspan + ' ' + IndSalesul + ' ' + IndSalesli + '</ul></li></ul></div></body>';
}
document.getElementById("myId").innerHTML += '<body><div id="myId1"><ul id="myUL"><li>' + Dubaispan + ' ' + Dubairul + ' ' + Dubaili + '</ul></li></ul></div><div id="myId1"><ul id="myUL"><li> ' + Qatarspan + ' ' + Qatarul + ' ' + Qatarli + '</ul></li></ul></div><div id="myId1"><ul id="myUL"><li> ' + Indiaspan + ' ' + IndSalesul + ' ' + IndSalesli + '</ul></li></ul><div id="myId1"><ul id="myUL"><li> ' + Punespan + ' ' + Puneul + ' ' + Puneli + '</ul></li></ul></div</div></body>';
}
});
}
</script>
<meta>
<meta>
<meta>
<meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta></head>
<body id="myId" onfocusout="parent.setEmailRange();" style="overflow-wrap: break-word;" data-new-gr-c-s-check-loaded="14.1098.0" data-gr-ext-installed="" data-new-gr-c-s-loaded="14.1098.0">
<grammarly-desktop-integration data-grammarly-shadow-root="true"></grammarly-desktop-integration>
</body></html>
[View:/cfs-file/__key/communityserver-discussions-components-files/117/SalesOrgTree030323.html:320:240]
I have attached Html file Please help for this .
Thanks & Regards,
Ajaya Kumar ch
+91-9113813508