RE: Count number of Activities per Opportunity
Hi ChrisCadden
Here is the JS codee
let globalVariables = {
Results: ""
};
function function1(_opportunityid) {
try {
var fetchData = {
"opportunityid": _opportunityid
};
var fetchXml = [
"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>",
" <entity name='activitypointer'>",
" <attribute name='activitytypecode'/>",
" <attribute name='activityid'/>",
" <link-entity name='opportunity' from='opportunityid' to='regardingobjectid' link-type='inner' alias='aa'>",
" <filter type='and'>",
" <condition attribute='opportunityid' operator='eq' uiname='ANIA Centres Partnership 2015' uitype='opportunity' value='", fetchData.opportunityid/*{98E4A92C-752B-E511-80FC-C4346BADF6A4}*/, "'/>",
" </filter>",
" </link-entity>",
" </entity>",
"</fetch>"
.join("");
function2("maa_donationdetailses", fetchXml);
if (globalVariables.Results.length > 0) {
//here you are
}
} catch (e) {
alert("function1: " e.message);
}
}
function function2(entitysPluralName, fetchXmlQuery) {
try {
var req = new XMLHttpRequest();
req.open(
"GET",
Xrm.Page.context.getClientUrl()
"/api/data/" globalVariables.WebAPIVersion "/" entitysPluralName "?fetchXml="
encodeURIComponent(fetchXmlQuery),
false
);//Sync
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);
globalVariables.Results = results.value;
} else {
alert(this.statusText);
}
}
};
req.send();
} catch (e) {
alert("function2: " e.message);
}
}
If I answer your question then please mark it as verified.
Let me know if I can provide you with more details.
Thanks
Regards,
Abdul Wahab
Power Platform & Customer Engagement Developer/Lead/Solution Architecture/Project Manager
Direct/WhatsApp: 923323281237
E-mail: abdulwahabubit@outlook.com
Skype: abdul.wahabubit
Linkedin: www.linkedin.com/.../