I have a web resource that takes input from the user and uses it to set the value of an attribute on the form. I have a simplified version of it below, where you can enter a value into a textbox and use the button to set the value on the attribute. I'm using this in a simplified test form, which in addition to the HTML web resource, also has the attribute on it, which is just a simple text field.
The problem is when the user is on the update form, if they use the web resource to set the attribute value, then instead of waiting for the form to auto-save, or manually saving the form, they navigate away from the page without editing any other fields, the changed value does not save. Before navigating away from the form, the icon in the lower right corner shows that there are unsaved changes, so CRM does know about the change, it just doesn't save it before navigating away. Also, if the user changes the value in the attribute's field directly, then the change saves before navigating away.
This is in CRM Online, version 1612 (8.2.0.774). The trouble is, we're moving away from CRM on-prem, where we have version 8.1.0.359. When I try the same code in that on-prem environment, the changed value does save.
Is there a way to change my code or form so that the changed value saves before the user navigates away in CRM online?
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script>
function setFormField() {
var attribute = parent.Xrm.Page.getAttribute("tre_amyfield1");
if (attribute) {
var value = document.getElementById("input").value;
attribute.setValue(value);
}
}
</script>
</head>
<body>
<input type="text" id="input"/>
<input type="button" onclick="setFormField();" value="Set Value"/>
</body>
</html>
Adding attribute.setSubmitMode("always") doesn't help, nor does adding attribute.fireOnChange(). If I add code to the OnSave event of the form, that code gets executed in our on-prem environment when the user navigates away, but not in the online environment.