Search code examples
javascriptvisual-studio-2013visual-studio-lightswitchlightswitch-2013

Lightswitch 2013 - HTML Client -> commitChanges() and showOtherPage() in union


just thought id ask on here as this is driving me insane... what im trying to do is commitChanges() or applyChanges(), followed my a myapp.showBrowseOtherScreen()

this is the way im trying to do it:

var result = confirm("Send Parcel?");
if (result == true) {
    screen.ProjectFinance.SendParcel = true;
    myapp.showBrowseInvoices();
}
else {
    msls.showMessageBox("Application Not Sent", { title: "Aborted" });
    myapp.cancelChanges();
    screen.ProjectFinance.SendParcel = false;
}
};

what it does currently is displays the message "Send Parcel", if i click OK, then it then brings up another option, as now that SendParcel has been set to true, there are unsaved changes on the page...

I need it to save and then navigate but im not sure what to try next, thanks for any help or advice


Solution

  • save(), saveChanges(), and commitChanges() are all asynchronous. So it starts the save operation, then tries to navigate away before the save is completed.

    myapp.commitChanges().then(function () {
        myapp.showBrowseInvoices();
    }
    

    The .then method takes up to two parameters. both functions, which can be defined in line like the example above, or calls to functions defined elsewhere. The first parameter is executed after successful completion of the operation, and the second is after failure.