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..
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
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
Hi Abhilash,
The regarding field is filled automatically when you create activity in the timeline.
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:
After:
Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.
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); } } }
Siv Sagar
149
Super User 2025 Season 1
Muhammad Shahzad Sh...
61
Most Valuable Professional
Daivat Vartak (v-9d...
53
Super User 2025 Season 1