Announcements
Hi Everyone,
Please assist, my requirement is to get a count of all activities per opportunity.
i.e
OpportunityId: e90a0493-e8f0-ea11-a815-000d3a1b14a2
Activities: 2 Emails, 3 Logged Calls
Output:
OpportunityId: e90a0493-e8f0-ea11-a815-000d3a1b14a2
Activity Count: 5
How would I go about retrieving this via the API endpoints? I need to loop through all opportunities and attain this count for all opportunities .
Thanks!
Hello ChrisCadden,
Using below shown FetchXMl you can get all activites for particular opportunity:
Hi ChrisCadden,
In case you used my described method then you need know about two things.
It is very simple if compared with your one.
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/.../
Thanks for your reply Abdul Wahab
Perhaps I need to supply some more context, we are using the opportunities API to fetch all the deals and storing them in our database.
Using the following:
/api/data/v9.0/opportunities?$expand=transactioncurrencyid($select=isocurrencycode),owninguser($select=firstname,lastname)&$filter=statecode%20eq%200
Based on the above endpoint, how can I now get a count of all the activities for these deals? Using the API's only.
Thanks,
Chris.
Yes it is necessary, we will be using this count/amount in an external system.
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/.../
Hi,
Is it necessary to get the amount through the API? Where will this data be used then?
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156