Calculation to show whether a lesson starts in the morning or the afternoon
I'm trying to set up a simple calculation in a timetable app which has the start and end time for the session in one date field (i.e. 17th September 10:00 - 12:15). I cannot split the start and end times into separate fields.
My calculation just needs to return a 1 for if the session starts in the morning, and 2 if the session starts in the afternoon - so that I can filter for morning and afternoon start times (since the filters in Podio only do date, not time, I can't use the native filters).
Currently my code is this:
var time = Number(moment(@TimetableDate).tz('Europe/London').format("HHmm"));
if (time > 0000 && time < 1159)
{ "1" }
else
{ "2" }
The preview shows 1 or 2, but the field is not echoing on the record - have I missed a step to make the number display?
I also can't get the field name to come up on the list of fields to filter by, which suggests that I've done something wrong and it's not recognised the calculation as a number field.
-
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 }
resultAlso 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
-
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.)
-
That code should return a number and make the calculation field a number type field.
Workaround: Entervar time = Number(moment(@TimetableDate).tz('Europe/London').format("HHmm"));
1Save. Come back and add the real calculation you want.
Btw: After saving your code did you refresh the app start page ? -
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!!
Please sign in to leave a comment.
Comments
4 comments