0

In my Editform I wish to reset all the ratingcounts on save, however I am getting an error message

Save Conflict. Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.

There is no other user. There is another update in the save action, which does a get / update on the ratings variable.

There is no overlap between the columns being updated on the editform and through the rating update code, so how can I force the code to accept both updates? The AllowUnsafeUpdates parameter does not seem to make any difference.

I am doing it this way as I don't know any other way of updating the ratings on the editform.

function MyPreSaveAction (){

// Update other fields on the item

var fieldvalue = 'Purple';

$("input[Title='Other field']").val(fieldvalue);

var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId);
var getweb = context.get_web();
getweb.AllowUnsafeUpdates = true;
var itemID = parseInt(GetUrlKeyValue('ID'));
var item = list.getItemById(itemID);

context.load(item, "RatingCount", "RatedBy","AverageRating");
item.set_item('AverageRating',5);
item.set_item('RatingCount',0);
item.set_item('RatedBy',[]);

item.update();
context.executeQueryAsync(RetrievedListID, ExecutionFailed);

//response handler

  function RetrievedListID(sender, args) {
    }

//error handler - generic

  function ExecutionFailed(sender, args) {
     }

getweb.AllowUnsafeUpdates = false;
var areOtherValid = typeof(__OriginalPreSaveAction) === "function" ? __OriginalPreSaveAction():true;

return amIValid && areOtherValid;
}

function RegisterMyPreSaveAction(){
  PreSaveAction = MyPreSaveAction;
}
  • Just spent a day looking at how to do this... finally... looks like the function window.onbeforeunload = function(){ update code } will do it. Now just have to work out which button was selected - cancel or save. – southskies Mar 29 '16 at 7:30
0

Solution did work.. code ended up as

iftosave = false;

function MyPreSaveAction (){
.
. 
. 
iftosave = true;
var areOtherValid = typeof(__OriginalPreSaveAction) === "function" ? __OriginalPreSaveAction():true;

return amIValid && areOtherValid;
}

function RegisterMyPreSaveAction(){
   PreSaveAction = MyPreSaveAction;
}

window.onbeforeunload = function(){

if (iftosave) {

var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId);
var getweb = context.get_web();
var itemID = parseInt(GetUrlKeyValue('ID'));
var item = list.getItemById(itemID);

context.load(item, "RatingCount", "RatedBy","AverageRating");
item.set_item('AverageRating',5);
item.set_item('RatingCount',0);
item.set_item('RatedBy',[]);

item.update();
context.executeQueryAsync(RetrievedListID, ExecutionFailed);

//response handler

function RetrievedListID(sender, args) {
  }

//error handler - generic

function ExecutionFailed(sender, args) {
 }
}
  • Hi, where is the amIValid variable original declared? are you missing some part of your code? Thanks in advance. – Noah Nov 8 '18 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.