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 365 | Integration, Dataverse...
Answered

Setting Regarding field in Activity entity using Javascript.

(0) ShareShare
ReportReport
Posted on by 595

Hi All,

I have an requirement saying I need to creating record in custom entity with associate to Activity entity. For getting the reference in Timeline i need to set regarding lookup in Activity.

I'm trying using javascript to achieve this.. please help me to do this..

I have the same question (0)
  • Verified answer
    prt33k Profile Picture
    6,907 on at
    RE: Setting Regarding field in Activity entity using Javascript.

    Hi Abhilash,

    Make these updates:

    1.regardingobject should also have entityname after underscore.

    let updateactivity = {

                              "regardingobjectid_syscm_case@odata.bind":"/syscm_cases("+case_ID+")"

                          };

    2. You cannot update activitypointer regarding directly - give the actual activity schema name :

    updateRecord("<email or task - schema name of entity>",entityId,updateactivity);

    Thanks,

    Prateek

  • Abhilash M abi Profile Picture
    595 on at
    RE: Setting Regarding field in Activity entity using Javascript.

    Check code snippet for your reference..

    let updateactivity = {

                               "RegardingObjectId@odata.bind":"/syscm_cases("+case_ID+")",

                           };

    console.log("case_ID id "+case_ID);

    console.log("entity id "+entityId);

    console.log("before window update");

    const result_activity = await window.parent.opener.Xrm.WebApi.updateRecord("activitypointer",entityId,updateactivity);

    I'm using this code inside HTML web resource

  • Community Member Profile Picture
    on at
    RE: Setting Regarding field in Activity entity using Javascript.

    Hi Abhilash,

    The regarding field is filled automatically when you create activity in the timeline.

    pastedimage1611554710429v1.png

    And regarding field is a special lookup field, which is oob field and it can store many related entities in it.

    If you want to use js to fill it, not just one name, id and entity type are also need.

    Just like example:

    function Regarding(executionContext) {
        var formContext = executionContext.getFormContext();
        //custom entity records value
        var regardingObjectId = "fa8d0b00-d35e-eb11-a812-0022481c13e5";
        var Name = "custom1";
        var type = "new_customentity";
    
        var value = new Array();
        value[0] = new Object();
        value[0].id = regardingObjectId;
        value[0].name = Name;
        value[0].entityType = type;
    
        formContext.getAttribute("regardingobjectid").setValue(value);
    }

    Test:

    Before:

    pastedimage1611561511564v6.png

    After:

    pastedimage1611561482927v5.png

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Suggested answer
    prt33k Profile Picture
    6,907 on at
    RE: Setting Regarding field in Activity entity using Javascript.

    IF you are trying to create email - you can use something like this. 

    Task and other are pretty similar... let me know if you need clarification for some specific type of activity

    function CreateEmail(executionContext) {
    	
    	var formContext = executionContext.getFormContext();
        //Regarding
    	var customEntityId = formContext.data.entity.getId(); //Change as required
        customEntityId = customEntityId.replace(/[{}]/g, "");
        
    	//Sender
    	var Owner = formContext.getAttribute("ownerid").getValue();
        OwnerId = Owner[0].id;
        OwnerId = OwnerId.replace(/[{}]/g, "");
        
    	//Recipient
    	var Customer = formContext.getAttribute("customerid").getValue();
        var AccountId = Customer[0].id;
        AccountId = AccountId.replace(/[{}]/g, "");
    
        var webapiPath = formContext.context.getClientUrl()   "/api/data/v9.0/emails";
        var email = {};
    	
        //Regarding
        email["regardingobjectid_quote@odata.bind"] = "/customEntity("   customEntityId   ")"; //Change as required
        email["subject"] = "Email";
        email["description"] = "Email Description";
    	
        var parties = [];
        
    	//ActivityParty Sender
        var sender = {};
        sender["partyid_systemuser@odata.bind"] = "/systemusers("   OwnerId   ")";
        sender["participationtypemask"] = 1; //From
    
        //ActivityParty Recipient
        var receiver = {};
        receiver["partyid_account@odata.bind"] = "/accounts("   AccountId   ")";
        receiver["participationtypemask"] = 2; //To 
        
    	
    	//add this to party
        parties.push(sender);
        parties.push(receiver);
    
        email["email_activity_parties"] = parties;
    
        var service = new XMLHttpRequest();
        service.open("POST", webapiPath, false);
        service.setRequestHeader("Accept", "application/json");
        service.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        service.setRequestHeader("OData-MaxVersion", "4.0");
        service.setRequestHeader("OData-Version", "4.0");
        service.send(JSON.stringify(email));
        if (service.readyState == 4 /* complete */) {
            if (service.status == 204) {
                Xrm.Utility.alertDialog('Record Created Successfully.');
            }
    		else {
                var error = JSON.parse(this.response).error;
                //show error
                Xrm.Utility.alertDialog(error.message);
            }
        }
    }

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 365 | Integration, Dataverse, and general topics

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 201

#2
DAnny3211 Profile Picture

DAnny3211 134

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 129 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans