Hi Jorge,
There are 2 ways to do.
1. Send an update request via API. You can generate the code with Dataverse REST Builder(created by Guido Preite)
2. Set attribute value and then call form save method.
Sample code:
function updateContactByAPIRequest(formContext) {
var contactId = formContext.data.entity.getId().slice(1, -1);
var record = {};
record.firstname = "XXXXX";
record.lastname = "XXXXX";
record.emailaddress1 = "abc@xyz.com";
record.telephone1 = null;
var req = new XMLHttpRequest();
req.open("PATCH", `${Xrm.Utility.getGlobalContext().getClientUrl()}/api/data/v9.0/contacts(${contactId})`, true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Prefer", "odata.include-annotations=*");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
// Success callback, you can do other logic here if needed.
} else {
console.log(this.responseText);
}
}
};
req.send(JSON.stringify(record));
}
function updateContactByFormSave(formContext) {
// Set attribute value as you want
formContext.getAttribute("firstname").setValue("XXXXX");
formContext.getAttribute("lastname").setValue("XXXXX");
formContext.getAttribute("emailaddress1").setValue("abc@xyz.com");
formContext.getAttribute("telephone1").setValue(null);
// Call save method
formContext.data.entity.save().then(
function () {
// Success callback, you can do other logic here if needed.
},
function (error) {
// Error callback
Xrm.Utility.alertDialog(error);
}
)
}