Create Email record in Dynamics 365 CE using JavaScript

Hi Everyone,

I know this could be very simple as we are doing this from ages but somehow I couldn’t get this piece of code very easily.

Code for creating email record using JavaScript in Dynamics 365 Customer Engagement. Important thing here to understand more on Activity Party Participation Type Mast. Go through Microsoft Docs for more information on the same.

var activityParties = []
    var Sender = {};
    var Receipent = {};

    var userId = "21EFAD11-353B-4238-93BB-65015F448E8A";

    // From - Participation Type Mask = 1
    Sender["partyid_systemuser@odata.bind"] = "/systemusers(" + userId + ")";
    Sender["participationtypemask"] = 1;

    // To - Participation Type Mask = 1
    Receipent["partyid_systemuser@odata.bind"] = "/systemusers(" + userId + ")";
    Receipent["participationtypemask"] = 2;

    var createEmailRequest = {
        "description": "This email is created using JavaScript Code",
        "regardingobjectid_account@odata.bind": "/accounts(bec28e1e-ab87-ea11-a817-000d3a19245f)",
        "subject": "Email using JavaScript",
        "email_activity_parties": activityParties

    Xrm.WebApi.createRecord('email', createEmailRequest).then(
        function success(Email) {
            console.log("Email has been created");
        function Error(e) {

Hope this helps.

Happy 365’ing

One thought on “Create Email record in Dynamics 365 CE using JavaScript

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s