Retrieve Activity Party using JavaScript and REST

An activity party represents a person or group associated with an activity. An activity can have multiple activity parties. There are 11 activity party types in Microsoft Dynamics CRM. The activity party type is stored as an integer value in the ActivityParty.ParticipationTypeMask attribute. The following table lists the different activity party types, the corresponding integer value for the ActivityParty.ParticipationTypeMask attribute, and the description.

Activity Party Type in CRM

We can get Activity Party by expanding One-to-many relationship between Activity Pointer and Activity Party (activitypointer_activity_parties). Whenever you create an activity record in Microsoft Dynamics CRM, a corresponding Activity Pointer record is created. Below is a method which you can use to retrieve Activity party.

 Method to retrieve “Call To” From Phone Call Entity

function retrieveCallTo(){
var id = Xrm.Page.data.entity.getId();
var query = encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/ActivityPointerSet?$select=Subject,activitypointer_activity_parties/ParticipationTypeMask&$expand=activitypointer_activity_parties&$filter= RegardingObjectId/Id eq guid'" + id + "'and ActivityTypeCode eq 'phonecall'");
var req = new XMLHttpRequest();
req.open("GET", query, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
 if (this.readyState === 4) {
 req.onreadystatechange = null;
 if (this.status === 200) {
 var returned = JSON.parse(req.responseText).d;
 var results = returned.results;
 for (var i = 0; i < results.length; i++) {
 var Subject = results[i].Subject;
 var ActivityPartyResults = results[i].activitypointer_activity_parties.results;
 var Callto = "";
 for (var j = 0; j < ActivityPartyResults.length; j++) {
 var ParticipationTypeMask = ActivityPartyResults[j].ParticipationTypeMask.Value;
 if (ParticipationTypeMask == 2) { // check for Call To Only
 Callto += ActivityPartyResults[j].PartyId.Name + ",";
 }
 }
 var n = Callto.lastIndexOf(",");
 var PartyNames = Callto.substring(0, n); // Party Names String having all the names in the Callto.
 }
 }
 else {
 alert(this.statusText);
 }
 }
};
req.send();
}


Leave a Reply

*

code