locked
How to cancel update in the (entity) updating event? (HTML client) RRS feed

Answers

  • //discard changes in current entity (e.g. in <entity>Updating) entity.Details.DiscardChanges(); //discard changes in the complete workspace

    this.DataWorkspace.ApplicationData.Details.DiscardChanges();



    paul van bladel


    • Edited by Paul Van Bladel Wednesday, August 7, 2013 5:09 PM restructure code
    • Marked as answer by TChiang Wednesday, August 7, 2013 6:51 PM
    Wednesday, August 7, 2013 5:08 PM

All replies

  • //discard changes in current entity (e.g. in <entity>Updating) entity.Details.DiscardChanges(); //discard changes in the complete workspace

    this.DataWorkspace.ApplicationData.Details.DiscardChanges();



    paul van bladel


    • Edited by Paul Van Bladel Wednesday, August 7, 2013 5:09 PM restructure code
    • Marked as answer by TChiang Wednesday, August 7, 2013 6:51 PM
    Wednesday, August 7, 2013 5:08 PM
  • A follow-up question:

    I am using commitChanges() and in the entity_Updating event I either continue to commit the change or use discardChanges(). And then I try to evaluate entityStatus() to see if the entity has been changed, but in both cases I get 'unchanged' status. What is the right way?


    Frank

    Thursday, August 8, 2013 2:47 PM
  • where did you find a CommitChanges() method?

    paul van bladel

    Thursday, August 8, 2013 4:35 PM
  • I am doing something like this:

    myapp.AccountEdit.SaveEditAccount_execute = function (screen) {
        // Write code here.
        myapp.commitChanges().then(function succeed() {
     var status = screen.Account.details.entityState;
            //this is where I got the 'unchanged' status
        },
        function fail(e) {
            // If error occurs, show the error.
            msls.showMessageBox(e.message, { title: e.title }).then(function () {
                // do something
            });
        });
    };

    Frank


    • Edited by TChiang Thursday, August 8, 2013 8:25 PM
    Thursday, August 8, 2013 8:11 PM
  • I am doing something like this:

    myapp.AccountEdit.SaveEditAccount_execute = function (screen) {
        // Write code here.
        myapp.commitChanges().then(function succeed() {
     var status = screen.Account.details.entityState;
            //this is where I got the 'unchanged' status
        },
        function fail(e) {
            // If error occurs, show the error.
            msls.showMessageBox(e.message, { title: e.title }).then(function () {
                // do something
            });
        });
    };

    Frank


    Then this may also work for you:

    myapp.BrowseCustomers.CommitChanges_execute = function (screen) {
    
        screen.getCustomers().then(function (customers) {
    
            // Delete selected
    
            customers.deleteSelected();
    
            // Save changes
    
            myapp.commitChanges().then(null, function fail(e) {
    
    
                // If error occurs, show the error.
    
                msls.showMessageBox(e.message, { title: e.title }).then(function () {
    
                    // Cancel Changes
    
                    myapp.cancelChanges();
    
                    throw e;
    
                });
    
    
            });
    
        });
    
    };
    

    see: Deleting Data In The Visual Studio LightSwitch HTML Client


    Unleash the Power - Get the LightSwitch HTML Client book

    http://LightSwitchHelpWebsite.com

    Thursday, August 8, 2013 9:58 PM
  • Thanks. I was following this example in my code but discardChanges() in entity_Updating doesn't trigger the fail function.


    Frank

    Friday, August 9, 2013 1:55 PM
  • Is this to me or to Michael? Maybe better to mention if you are talking about java script code or .net code...

    What Do you mean by fail function. When DiscardChanges is called on an entity, it's doing things as advertised: discarding the changes of the current entity.


    paul van bladel


    Friday, August 9, 2013 2:03 PM
  • Is this to me or to Michael? Maybe better to mention if you are talking about java script code or .net code...

    What Do you mean by fail function. When DiscardChanges is called on an entity, it's doing things as advertised: discarding the changes of the current entity.


    paul van bladel



    Yes, because my code example will only work in JavaScript :)

    Unleash the Power - Get the LightSwitch HTML Client book

    http://LightSwitchHelpWebsite.com

    Friday, August 9, 2013 2:49 PM
  • @Michael: Well, maybe... one day... LightSwitch might support http://nodejs.org/ and then there is java script all over the place :)


    paul van bladel

    Friday, August 9, 2013 3:02 PM
  • Haha, I am definitely confusing the server side and the client side code. So DiscardChanges() on the server side doesn't result in commitChanges() on the client side to detect as a failure therefore the fail(e) function to get triggered? What does?

    Frank

    Friday, August 9, 2013 3:56 PM