Attempting to update records from an attached OData or SharePoint data source, using the HTML client, results in the runtime error:
"Save operation failed. The etag value in the request header does not match with the current etag of the object"
The work around for this issue is to add the following <script> element to the default.htm file that is part of the HTML Client project, just below the last script element within the <body> element:
<script type=
"text/javascript"
>
var
origMetadataReadFunc = OData.metadataHandler.read;
OData.metadataHandler.read =
function
(response, context) {
origMetadataReadFunc.call(OData.metadataHandler, response, context);
data = response.data,
schema = data && data.dataServices && data.dataServices.schema && data.dataServices.schema[0],
entities = schema && schema.entityType || [];
entities.forEach(
(entity) {
i,
property,
properties = entity.property || [];
for
(i = properties.length - 1; i >= 0; i--) {
property = properties[i];
if
(property.name ===
"Microsoft_LightSwitch_ETag"
) {
property.type =
"Edm.String"
;
break
}
});
};
origJsonReadFunc = OData.jsonHandler.read;
OData.jsonHandler.read =
result = origJsonReadFunc.call(OData.jsonHandler, response, context);
data = response.data, results = data.results;
(results) {
results.forEach(
(entity.__metadata.etag) {
etag = entity.__metadata.etag,
firstIndex = etag.indexOf(
"'"
),
lastIndex = etag.lastIndexOf(
coreEtag =
""
(
i = firstIndex + 1; i < lastIndex; i++) {
char = etag[i];
coreEtag += char;
(char ==
coreEtag +=
(etag[i + 1] ==
i++;
entity.__metadata.etag = etag.substr(0, firstIndex + 1) + coreEtag + etag.substr(lastIndex);
return
result;
</script>