I've worked thru a form for all kinds of input and right now I'm struggling a bit to set (or rather PATCH) the value holding the selected value of the option set. Now, for all other types the following code works great (for its field):
var json =
{
"tuv_optionsetalternative": selectedValue
};
PatchEntity(id, "tuv_servicetasks", json);
Here I'm making json where i set the tuv_optionsetalternative to the selected value with the function PatchEntity. The selectedValue is the GUID of the selected lookup value. Its looks like this:
function PatchEntity(id, entityName, json) {
var req = new XMLHttpRequest();
req.open("PATCH", encodeURI(Xrm.Page.context.getClientUrl() + "/api/data/v8.1/" + entityName + "("+ id +")"), true);
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function ()
{
if (this.readyState == 4)
{
req.onreadystatechange = null;
if (this.status == 204) {
Debug("Successfully updated entity.");
Debug(json);
} else {
Debug("Could not patch entity.")
Debug(json);
}
}
}
req.send(JSON.stringify(json));
}
This does not work. I get "Could not patch entity." for patching this lookup only, all the others are fine.
*This post is locked for comments
I have the same question (0)