locked
Lightswitch HTML CLIENT - Force a property change RRS feed

  • Question

  • Hello,

    my question is simple (i think). Imagine on an Entity that has a datetime field (DateProperty) that i want to programatically change the hours and minutes, and then commitChanges().
    So i have two local properties named "hours" and "minutes".

    To change DateProperty i use the following code:

    screen.Entity.DateProperty.setHours(screen.hours, screen.minutes);

    By only doing this, the app doesn't assume that the property has changed its value (even though the value is changed).

    1. isChangedfalse
    2. isEditedfalse
    3. isReadOnlyfalse
    4. name"DateProperty"
    5. onchangeundefined
    6. originalValueundefined

    7. valueWed Sep 16 2015 16:06:00 GMT+0100 (Hora de Verão de GMT)

    I get this above with:

    screen.Entity.details.properties.DateProperty
    The value is the correct one, but i assume that when commiting the changes this property is seen as not Changed, so it's not saved into the Database. I have already tried forcing to change isChanged and isEdited but it's not working it allways assumes the value false.
    screen.Entity.details.properties.DateProperty.isChanged = true;
    screen.Entity.details.properties.DateProperty.isChanged = true;
    anyone knows a way i can make this work?

    Best regards,
    Johny

    Wednesday, November 11, 2015 12:13 PM

Answers

  • Sorry for late response.

    This was the code i was using:
    myapp.AddEditEntity.mySaveBtn_execute = function (screen) {
       screen.Entity.DateProperty.setHours(screen.hours, screen.minutes);
       screen.Entity.details.properties.DateProperty.isChanged = true;
       screen.Entity.details.properties.DateProperty.isEdited = true;
       myapp.commitChanges();
    };
    Meanwhile, i found another "way" of solving my problem, i just created a function that changes the DateProperty directly, and returns to it's original value, just to assume that the property has been changed. So each time hours or minutes are changed i run fakeDateChange.
    function fakeDateChange(itemName, screen) {
        var originalDate = screen.findContentItem(itemName).value;
        screen.findContentItem(itemName).value = new Date();
        screen.findContentItem(itemName).value = new Date(originalDate);
    }

    Best regards,
    Johny
    • Edited by Johny Pingo Monday, November 16, 2015 12:11 PM
    • Marked as answer by Johny Pingo Thursday, November 19, 2015 10:41 AM
    Monday, November 16, 2015 9:35 AM

All replies

  • Can you post the full code where you are calling commitChanges?  With commitChanges you would be saving the changes and navigating back to the previous screen?  It may be that you need to refresh the collection on the previous screen to see the update values from the server, or access the updated values in an afterClosed function.  It's difficult to say without seeing the whole scenario.  
    Wednesday, November 11, 2015 4:54 PM
  • Sorry for late response.

    This was the code i was using:
    myapp.AddEditEntity.mySaveBtn_execute = function (screen) {
       screen.Entity.DateProperty.setHours(screen.hours, screen.minutes);
       screen.Entity.details.properties.DateProperty.isChanged = true;
       screen.Entity.details.properties.DateProperty.isEdited = true;
       myapp.commitChanges();
    };
    Meanwhile, i found another "way" of solving my problem, i just created a function that changes the DateProperty directly, and returns to it's original value, just to assume that the property has been changed. So each time hours or minutes are changed i run fakeDateChange.
    function fakeDateChange(itemName, screen) {
        var originalDate = screen.findContentItem(itemName).value;
        screen.findContentItem(itemName).value = new Date();
        screen.findContentItem(itemName).value = new Date(originalDate);
    }

    Best regards,
    Johny
    • Edited by Johny Pingo Monday, November 16, 2015 12:11 PM
    • Marked as answer by Johny Pingo Thursday, November 19, 2015 10:41 AM
    Monday, November 16, 2015 9:35 AM
  • Good one, glad you got it working.
    Monday, November 16, 2015 1:53 PM