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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Update Activity Party Odata / Change From of Email via Javascript

(1) ShareShare
ReportReport
Posted on by 60

Hello all,

I'm trying to update an activity party by Odata call, however, i'm facing issues to achieve that.

Basically, i've a requirement that sometimes we receive one email, and we want to change the sender. For that we've created one html form where the user can search by contacts and then set it into email. 

I've created a piece of javascript code, however when i apply it, it changes the sender but at the same time erases all the recipients also CC and BCC content.

On below there is the piece of code that i've used to test.

Did someone already done something like this or have a workaround or another way to achieve it? I'm on version 8.2.

//first try, to set the lookup value 
//didn't worked because the from that we are trying to set is systemuser.
function SetEmailFrom() {

    var contactID = "<contactId>";
    var object = new Array();
    object[0] = new Object();
    object[0].id = contactID;
    object[0].name = <name>;
    object[0].entityType = "<entity type>";

    
    window.top.opener.frames[0].Xrm.Page.getAttribute("from").setValue(object);
}


Now with odata trying to set the the "From"

/with this code, i'm able to set the "From" but the recipient,CC and BCC are erased.
function SetEmailContact(contGui) {
    var emailGuid = window.top.opener.frames[0].Xrm.Page.data.entity.getId();
    var emailGuidClean = emailGuid.replace('{', '').replace('}', '');
    var entity = {};
    var parties = [];
    //ActivityParty (From)
    var sender = {};
    sender["partyid_contact@odata.bind"] = "/contacts(" + contGui + ")";
    sender["participationtypemask"] = 1; //From
    //add this to collection
    parties.push(sender);
    entity["email_activity_parties"] = parties;
    var queryToAssignEmail = "/api/data/v8.2/emails(" + emailGuidClean + ")";
    alert(queryToAssignEmail);
    var req = new XMLHttpRequest();
    req.open("PATCH", Xrm.Page.context.getClientUrl() + queryToAssignEmail, 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.setRequestHeader("If-Match", "*");
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 204) {
                //Success - No Return Data - Do Something
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send(JSON.stringify(entity));
}


If i try to update or create an activity party on the ActivityParty entity, it says that is not possible to create and update this entity.

Could you please give a hint about this?

Thank you in advance

Best Regards,

DR

*This post is locked for comments

I have the same question (0)
  • Ruben Raposo Profile Picture
    60 on at
    RE: Update Activity Party Odata

    Hi Guys,

    Any idea about this?

    Basically what is struggling us is the fact that we are not able to change the "from" of  email via Javascript.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans