locked
LightSwitch html wait for promise beforeApplyChanges RRS feed

  • Question

  • Hi

    In my LightSwitch html application in the beforeApplyChanges function i'm making an ajax call and i want the application should wait till the promise operation is done and then it should save the changes, So how can i do that?

    This is my code inside beforeApplyChanges :

    return new msls.promiseOperation(function (operation) {
                $.ajax({
                    type: 'post',
                    data: {
                        Count: newStaffs.length
                    },
                    url: '../../GenerateIDs.ashx',
                    success: function success(result) {
                        var ids = result.split(",");
                        ids.forEach(function (id, index) {
                            newStaffs[index].StaffId = id;
                        });
                        operation.complete(); // I want the function shouldn't exit till now
                    },
                    error: function err(jqXHR, textStatus, errorThrown) {
                        operation.error(errorThrown);
                    }
                });
            });
    Thanks

    Sunday, July 12, 2015 4:10 PM

Answers

  • You can issue a SQL statement that could make the search for an open ID faster. For an example see:

    Sending Asynchronous Emails Using LightSwitch HTML Client

    In this example I am inserting into the database but you could easily construct an update command that would run very fast.

                // Insert into the database
                string connString =
                    System.Web.Configuration.WebConfigurationManager
                    .ConnectionStrings["_IntrinsicData"].ConnectionString;
    
                SqlConnection conn = new SqlConnection(connString);
                string sql = "INSERT INTO MessageLogs (LogMessage, Created) VALUES (@LogMessage, @Created)";
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@LogMessage", LogMessage);
                cmd.Parameters.AddWithValue("@Created", DateTime.UtcNow);
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
                conn.Close();
    

     

    Unleash the Power - Get the LightSwitch 2013 HTML Client / SharePoint 2013 book

    http://LightSwitchHelpWebsite.com

    • Marked as answer by Angie Xu Monday, July 20, 2015 9:01 AM
    Monday, July 13, 2015 3:12 PM

All replies