Calculation to show whether a lesson starts in the morning or the afternoon

Comments

4 comments

  • Rainer Grabowski

    Hey Susan,

    first: It should be 

    if (time > 0 && time < 1200)

    because 0000 isn't a number. 
    But the main mistake in your code is that you wrap 1 and 2 in quotation marks - that makes 1 and 2 a (text) string, but you need them as a number: 

    var time = Number(moment(@TimetableDate).tz('Europe/London').format("HHmm"));
    var result = 0;
    if (time > 0 && time < 1200)
    { result = 1 }
    else
    { result = 2 }
    result

    Also check if the calculation field is number type (it seems it is because the string "1" and "2" don't show up in the item.  Best: Delete the existing field and create a new one with the code above. 

    Rainer

    0
    Comment actions Permalink
  • Susan Warren

    OK - after a bit of a delay the number is showing on the record, so the calculation works.

    However - Podio has clearly decided that this is a text calculation, which is why I can't filter by it. I know that I'll need to delete and recreate the calculation, but is there anything I need to change to make it register as a number field? (I've tried recreating it already and again it seems to think this is a text field, so I can't add it to the filter.)

    0
    Comment actions Permalink
  • Rainer Grabowski

    That code should return a number and make the calculation field a number type field. 
    Workaround: Enter

    var time = Number(moment(@TimetableDate).tz('Europe/London').format("HHmm"));
    1

    Save. Come back and add the real calculation you want. 
    Btw: After saving your code did you refresh the app start page ? 

    0
    Comment actions Permalink
  • Susan Warren

    Hi Rainer - thank you for responding! I hadn't seen your first message when I commented yesterday, so my comment was about my code and not the fix.

    The field was definitely registering as a text field when I first tried, but your fix has worked perfectly and the (new) calculation is a number field, so I can set up my filters. Thank you!!

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk