Shambhu

Shambhu

  • NA
  • 81
  • 38.2k

Save operation fail on applyChangs call in Lightswitch html

Jan 16 2015 3:06 PM

Lightswitch Html Client:

Save operation fail on second applyChangs call with error "the data you are editing has been updated by another transaction"

Getting the mentioned error in below code.


Functionalities are 1. save as draft(save without validation) and 2. click on next(save and next page).

1. Save as draft.

myapp.AddFinState.Save_execute = function (screen) {
    try {
        isDraft = true;
        myapp.applyChanges().done(function () {
            //window.location.reload();
            //myapp.showBrowseRefresh(null, screen.UserID, screen.UserName, screen.RoleType);
        });

        //myapp.activeDataWorkspace.FSCPDB.saveChanges().then(function () {
        //    window.location.reload();
        //});
        alert("Your draft has been saved successfully.");

    }
    catch (e) {
        console.log("Error in AddFinState.Save_execute. " + e.description);
    }

};



2. Save & next page


myapp.AddFinState.SubmitNext_execute = function (screen) {
    try {
        //myapp.applyChanges().then(null, function fail(e) {
        //    msls.showMessageBox(e.message, { title: e.title })
        //});
        myapp.applyChanges().done(function () {
            myapp.activeDataWorkspace.FSCPDB.FinancialSurveyRecords_SingleOrDefault(screen.UserID).execute().then(function (data) {

                if (data.results[0] != null) {
                    myapp.showAddFinRecord(data.results[0], screen.UserID, screen.UserName, screen.RoleType);
                }
                else {
                    myapp.showAddFinRecord(null, screen.UserID, screen.UserName, screen.RoleType, {
                        beforeShown: function (addEditScreen) {
                            addEditScreen.FinancialSurveyRecord = new myapp.FinancialSurveyRecord();
                        }
                    });
                }
            })
        })
    }
    catch (e) {
        console.log("Error in AddFinState.SubmitNext_execute. " + e.description);
    }
};

Please help in rectifying with code snippet.


Regards,

Sham