Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Append Values to Activity Party "To" Field using WebAPI Update & Javascript

(0) ShareShare
ReportReport
Posted on by 5

Hi,

I am currently working on a custom activity entity where I have to update the "To" field - dynamically adds up with user records as recipients, via PCF Control.

Here is my code:

//this will get the activity entity and the multi-table/lookup or polymorphic lookup "To" field (activity_parties)

//once retrieved, create new partylist then push to add it to the existing activity partylist

then update

context.webAPI.retrieveMultipleRecords("entityName", "?$expand=entityName_activity_parties($select=participationtypemask)&$filter=_regardingobjectid_value eq " + this._currentEntity.id).then(
(result) => {
for (var i = 0; i < result.entities.length; i++) {
var activityid = result.entities[i]["activityid"];
var activity_parties = result.entities[i]["entityName_activity_parties"];
}
var updateData: { [key: string]: any } = {};
let newPartyList: any;

newPartyList = {
"participationtypemask": 2,
"partyid_systemuser@odata.bind": "/systemusers(" + userid + ")"
}
activity_parties.push(newPartyList);
updateData = {
"entityName_activity_parties": activity_parties,
}
this._context.webAPI.updateRecord(entityName, activityid, updateData);

*newPartyList was pushed to existing activity_parties (thru debugging) but as I checked the To field, no values has been added. 

I found some links with the same scenario using Xrm.Page.getAttribute("to").setValue(partlistData); --which is not applicable to my code/web api call or is there something I am missing?

https://powerobjects.com/development/populate-crm-2011-lookup-partylist-field-javascript/

https://rajeevpentyala.com/2012/04/02/get-and-set-partylist-fields-using-jscript/

Thank you.

  • Suggested answer
    riko4 Profile Picture
    riko4 5 on at
    RE: Append Values to Activity Party "To" Field using WebAPI Update & Javascript

    Hi,

    Just an update to this post.

    I finally get this working using

    webAPI.retrieveMultipleRecords("activityparty", "?$select=participationtypemask,_partyid_value&$filter=_activityid_value eq " + entityId).
    To retreive the current activity parties then store the objects with participationtypemask = 1 (From) and 2 (To) to an array.
    I now then push the new parties to the same array then update the entity record.
    These are the helpful links I also found:
    Please let me know if there is a better way.
    Thank you.
  • riko4 Profile Picture
    riko4 5 on at
    RE: Append Values to Activity Party "To" Field using WebAPI Update & Javascript

    Hi Mehdi,

    Please see below for details:

    activity_parties: Array(4)
    0:
    @odata.etag: "W/\"139728979\""
    activitypartyid: "16579059-4657-ec11-8f8f-00224840a19b"
    participationtypemask: 1
    participationtypemask@OData.Community.Display.V1.FormattedValue: "Sender"
    _activityid_value: "aaca22b0-0e57-ec11-8f8f-00224840a19b"
    _activityid_value@Microsoft.Dynamics.CRM.associatednavigationproperty: "activityid_activitypointer"
    _activityid_value@Microsoft.Dynamics.CRM.lookuplogicalname: "activitypointer"

    pastedimage1639052789948v1.png

    Thank you.

  • meelamri Profile Picture
    meelamri 13,206 User Group Leader on at
    RE: Append Values to Activity Party "To" Field using WebAPI Update & Javascript

    Hi,

    Can you please share your logs ? I would like to see the value of the activity_parties list in more detail...

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,784 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,476 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans