web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to create "activityparty" reference using Web Api Preview(OData)?

(0) ShareShare
ReportReport
Posted on by 1,505

hi there,

I'm creating new phone call activity record using the Dynamics CRM web API(OData) using System.Net.Http.HttpClient. This code is working fine given below:

#region Create a entity
                    // Create PhoneCall Activity using the early-bound class.
                    PhoneCall call = new PhoneCall();
                    call.subject = "Contoso";
                    call.description = "555-5555";

                    // It is a best practice to refresh the access token before every message request is sent. Doing so
                    // avoids having to check the expiration date/time of the token. This operation is quick.
                    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", auth.AcquireToken().AccessToken);
                    
                    // Send the request, and then check the response for success.
                    // POST api/data/accounts
                    HttpResponseMessage response =
                        await HttpClientExtensions.SendAsJsonAsync<PhoneCall>(httpClient, HttpMethod.Post, "api/data/phonecalls", call);

                    if (response.IsSuccessStatusCode)
                        Console.WriteLine("PhoneCall Activity '{0}' created.", call.subject);
                    else
                        throw new Exception(String.Format("Failed to create PhoneCall Activity '{0}', reason is '{1}'.",
                                            call.subject, response.ReasonPhrase), new CrmHttpResponseException(response.Content));
                    #endregion Create a entity


Now my question is that, how i can create activityparty reference using the web api preview?

call.to = ?
call.from = ?

your response will be appreciated.
thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Hi,

    Here is the SDK version of how you would set the From address, you should be able to use the same thing, maybe some small tweaks needed:

    .from = new ActivityParty[] { new ActivityParty { PartyId = new EntityReference("the_entityname", the_entityid) } };

    If this helps, I'd appreciate if you would mark this as the verified answer.

    Thanks,

    Aiden

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
  • Suggested answer
    efefher Profile Picture
    on at

    In case anyone is still looking for answer to this. 

    var owner = "/systemusers(00000000-0000-0000-0000-000000000000)";
    var customer = "/accounts(00000000-0000-0000-0000-000000000000)";
    
    var activityParties = new Array();
    var partyFrom = {"partyid_systemuser@odata.bind" : owner, "participationtypemask" : 1};
    var partyTo = {"partyid_account@odata.bind" : customer, "participationtypemask" : 2};
    activityParties[0] = partyFrom;
    activityParties[1] = partyTo;
    
    var call = {};
    call["phonecall_activity_parties"] = activityParties;
    
    var req = new XMLHttpRequest();
    req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/phonecalls", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    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 === 204) {
                Xrm.Utility.alertDialog("Call created successfully!");
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send(JSON.stringify(call));

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans