locked
LightSwitch HTML Client refresh problem RRS feed

  • Question

  • Hi,

    I am new to lightswitch and have a problem with the html client. I have a problem when i refresh using the browser's refresh button.

    When I clicked on an item in the list, i will set the Hub property to be the Hub on the screen. After i clicked the refresh, i am unable to assign the Hub property.

    Before refresh, item.Hub = screen.Hub will set the Hub property.

    After refresh, item.Hub will remain null.

    myapp.ViewHub.SignIn_execute = function (screen) {
        var item = screen.EmployeeStatusSet0.selectedItem;
        item.PreviousStatus = 0;
        item.Status = 1;
        item.Hub = screen.Hub;
    
        screen.closePopup();
        return myapp.activeDataWorkspace.ApplicationData.saveChanges().then(function () {
            screen.EmployeeStatusSet0.refresh();
            screen.EmployeeStatusSet1.refresh();
            return true;
        });
    };

    Thanks and Regards,

    Chin Sin

    Wednesday, December 25, 2013 2:06 PM

Answers

  • The problem was solved after I added validation. After i set the entity.Hub = screen.Hub, the validation prompted the error message, then i set the entity.Hub = screen.Hub and it works.

    partial void EmployeeStatusSet_Validate(EmployeeStatus entity, EntitySetValidationResultsBuilder results)
            {
                if (entity.Status != 0 && entity.Hub == null)
                    results.AddEntityError("Sign in failed. Please try again. If the problem persists, please restart the application in a new window.");
            }

    • Marked as answer by Chin Sin Friday, December 27, 2013 2:22 PM
    Friday, December 27, 2013 2:22 PM

All replies

  • Hi, I think you have to set the focus to the selecteditem because when refresh the focus is lost

    Sven Elm

    Wednesday, December 25, 2013 3:49 PM
  • Hi Sven,

    Thank you for your reply.

    This is what I observed.

    1. After the browser's refresh, the EmployeeStatus entity shows that the Hub property is set to the screen.Hub.
    2. The Activity entity is created with no Hub. (Normally, it is created with EmployeeStatus.Hub)
    3. After clicking browser's refresh 2nd time, the EmployeeStatus entity is showing null in the Hub property.
    	partial void EmployeeStatusSet_Updating(EmployeeStatus entity)
            {
                if ((entity.PreviousStatus == 0 && entity.Status == 1) ||
                    (entity.PreviousStatus == 1 && entity.Status == 2) ||
                    (entity.PreviousStatus == 1 && entity.Status == 3))
                {
                    EmployeeActivity activity = this.DataWorkspace.ApplicationData.EmployeeActivities.AddNew();
    
                    activity.Type = entity.Status;
                    activity.EmployeeStatus = entity;
                    activity.Hub = entity.Hub;
                    activity.Status = "Open";
    
                }
                else if ((entity.PreviousStatus == 1 && entity.Status == 0) ||
                    (entity.PreviousStatus == 2 && entity.Status == 1) ||
                    (entity.PreviousStatus == 3 && entity.Status == 1))
                    EmployeeActivity activity = this.DataWorkspace.ApplicationData.EmployeeActivities.Where(x => x.Status == "Open" && x.EmployeeStatus.Id == entity.Id && x.Type == entity.PreviousStatus).FirstOrDefault();
                    if (activity != null)
                    {
                        activity.Status = "Closed";
                    }
                }
            }


    • Edited by Chin Sin Wednesday, December 25, 2013 5:35 PM
    Wednesday, December 25, 2013 5:33 PM
  • The problem was solved after I added validation. After i set the entity.Hub = screen.Hub, the validation prompted the error message, then i set the entity.Hub = screen.Hub and it works.

    partial void EmployeeStatusSet_Validate(EmployeeStatus entity, EntitySetValidationResultsBuilder results)
            {
                if (entity.Status != 0 && entity.Hub == null)
                    results.AddEntityError("Sign in failed. Please try again. If the problem persists, please restart the application in a new window.");
            }

    • Marked as answer by Chin Sin Friday, December 27, 2013 2:22 PM
    Friday, December 27, 2013 2:22 PM