locked
LightSwitch HTML client. new save and new again loop RRS feed

  • Question

  • I have an LightSwitch html client application. In one screen with 4 text fields i want after a record is saved:

    1. Instead of navigating to the previous screen - reopen the form in add mode (save and new mode).

    2. In the new record some of the fields  I want to be populated with the same data as the last succesfull save.

    Thanks

    Wednesday, June 10, 2015 7:27 PM

Answers

  • Michael's article above is very good to learn more about the built-in navigation API and you probably want to do something like the following:

    1. Hide the standard Save button and implement your own Save button so that you have control over what happens when you click the Save button. Use the following code in the _postRender() event of the first main tab of the edit screen to hide the standard Save button (try one or both of the lines below as I cannot exactly remember which of the lines pertains to the Save button, although it might be the second):

    setTimeout(function () {
    	$(element).parent().closest(".msls-dialog").find("[data-ls-tap='tap:{data.shell.okCommand.command}']").hide();
    	$(element).parent().closest(".msls-dialog").find("[data-ls-tap='tap:{data.shell.saveCommand.command}']").hide();
    });

    2. Add your own Save button to the screen command bar and add the following code into the _execute() event:

    // save the newly added entity and remain on the current screen
    msls.application.applyChanges().then(
    	function success() {
    		// save was successful, now create a new entity to repeat the process
    		// you can remove the showMessageBox() if not required
    		msls.showMessageBox("Record saved successfully", { title: "Success }).then(function () {
    			screen.Client = new myapp.Client();
    		});
    	},
    	function fail(e) {
    		// If an error occurs, show the error.
    		msls.showMessageBox(e.message, { title: e.title }).then(function () {
    		});
    	}
    );



    Regards, Xander. My Blog

    • Edited by novascape Wednesday, June 10, 2015 10:51 PM
    • Marked as answer by Nikolakis Thursday, June 11, 2015 1:56 PM
    Wednesday, June 10, 2015 10:50 PM
  • Thanks a lot for the help. Worked !

    In order to populate the new record 

    screen.Client = new myapp.Client()

    with data from the last saved record I use global variables to save previous values

    msls.myglobalvar = screen.client.fieldname;


    // save the newly added entity and remain on the current screen msls.application.applyChanges().then(

    //save value of the field name to myglobalvar

    msls.myglobalvar = screen.client.fieldname; function success() { // save was successful, now create a new entity to repeat the process // you can remove the showMessageBox() if not required msls.showMessageBox("Record saved successfully", { title: "Success }).then(function () { screen.Client = new myapp.Client();

    //restore myglobalvar to the new record

    screen.client.fieldname = msls.myglobalvar; }); }, function fail(e) { // If an error occurs, show the error. msls.showMessageBox(e.message, { title: e.title }).then(function () { }); } );


    • Marked as answer by Nikolakis Friday, June 12, 2015 6:09 PM
    Thursday, June 11, 2015 2:10 PM

All replies

  • Michael's article above is very good to learn more about the built-in navigation API and you probably want to do something like the following:

    1. Hide the standard Save button and implement your own Save button so that you have control over what happens when you click the Save button. Use the following code in the _postRender() event of the first main tab of the edit screen to hide the standard Save button (try one or both of the lines below as I cannot exactly remember which of the lines pertains to the Save button, although it might be the second):

    setTimeout(function () {
    	$(element).parent().closest(".msls-dialog").find("[data-ls-tap='tap:{data.shell.okCommand.command}']").hide();
    	$(element).parent().closest(".msls-dialog").find("[data-ls-tap='tap:{data.shell.saveCommand.command}']").hide();
    });

    2. Add your own Save button to the screen command bar and add the following code into the _execute() event:

    // save the newly added entity and remain on the current screen
    msls.application.applyChanges().then(
    	function success() {
    		// save was successful, now create a new entity to repeat the process
    		// you can remove the showMessageBox() if not required
    		msls.showMessageBox("Record saved successfully", { title: "Success }).then(function () {
    			screen.Client = new myapp.Client();
    		});
    	},
    	function fail(e) {
    		// If an error occurs, show the error.
    		msls.showMessageBox(e.message, { title: e.title }).then(function () {
    		});
    	}
    );



    Regards, Xander. My Blog

    • Edited by novascape Wednesday, June 10, 2015 10:51 PM
    • Marked as answer by Nikolakis Thursday, June 11, 2015 1:56 PM
    Wednesday, June 10, 2015 10:50 PM
  • Thanks a lot for the help. Worked !

    In order to populate the new record 

    screen.Client = new myapp.Client()

    with data from the last saved record I use global variables to save previous values

    msls.myglobalvar = screen.client.fieldname;


    // save the newly added entity and remain on the current screen msls.application.applyChanges().then(

    //save value of the field name to myglobalvar

    msls.myglobalvar = screen.client.fieldname; function success() { // save was successful, now create a new entity to repeat the process // you can remove the showMessageBox() if not required msls.showMessageBox("Record saved successfully", { title: "Success }).then(function () { screen.Client = new myapp.Client();

    //restore myglobalvar to the new record

    screen.client.fieldname = msls.myglobalvar; }); }, function fail(e) { // If an error occurs, show the error. msls.showMessageBox(e.message, { title: e.title }).then(function () { }); } );


    • Marked as answer by Nikolakis Friday, June 12, 2015 6:09 PM
    Thursday, June 11, 2015 2:10 PM