Chaining multiple formulas with "&&" limits?

Am I doing something wrong or is there a limit of how many formulas can be chained when setting composite components private variable’s value through formula?

The formula below does not function properly, it only sets the “date” and “minute” component and skips the “hour” component. However, when I separated the set private variable into a chained flow function it worked and set all the required components correctly.

And here is the working setup (the set variable functions are the same as above, just in the first set variable function there are only 1 “&&”…):

First, what is the intent of this first expression?

SET_DATETIME_COMPONENT(privateVars.selected_date, GET_DATETIME_COMPONENT(privateVars.selected_date, “date”),“date”)

This appears to have no effect since it extracts the date portion of privateVars.selected_date and then surgically reinserts this as the date of that same variable. Probably not what you intended.

Keep in mind that && is really just an AND for compound boolean expressions. Using && as a way to perform multiple functions in the way you’re doing it will only behave in a useful way if the following two things are guaranteed:

  1. Each sub-expression has a value that is interpreted as TRUE (if a FALSE is encountered, the entire expression is known to be FALSE and the rest don’t need run or evaluated)
  2. Each sub-expression has to do something useful on it’s own. It’s return value is meaningless and just has to be TRUE (as stated in 1) to keep running all the following sub-expressions

SET_DATETIME_COMPONENT() always returns a datetime, so I think 1) above is satisfied.
But that function doesn’t modify the variable you provide, it returns the modified datetime as the return value. Each of the SET_DATETIME_COMPONENT(), assuming they all get run, start with the original privateVars.selected_date, modifies it’s one piece, and then throws that away. Or maybe one of them gets used as the variable assignment, but I don’t think that’s what you were trying to do.

Reading between the lines, it seems what you want to do is take a datetime and modify the date, hour, and minute with new values, and then assign that to the variable. The way I would do that is to nest your 3 functions so that the result of each modification is fed into the next function, whose result is fed into the next function, etc. The result of the final function is used as the value to assign to the private variable.

Something like this (shown on multiple lines for clarity – collapse these into 1 line when entering, of course):

SET_DATETIME_COMPONENT(
SET_DATETIME_COMPONENT(
SET_DATETIME_COMPONENT(privateVars.selected_date, newDate, “date”),
newMinute, “minute”),
newHour, “hour”)

Where newDate, newMinute, and newHour are numeric values that you want to use as the replacement values in the datetime value. Replace these with the values you really want to insert.

1 Like

Thank you very much for the comprehensive reply, this saved me tons of time and made the component so much faster. As the first step, I utilised your last advice, the nesting. And it already made a huge difference.

I will check all the other flow functions and correct them to fit your reply and get back here with some updates.

Thank you again. :pray:

I am new to using Appgyver and using in app formulas. I just try to figure out what is the best way to edit dates… this seems pretty basic but for some reason this doesn’t seem to work.


What I really want to do is learn how to generate list of week days starting from Monday.

@Mevi are there any formula examples for generating list of week days? I checked your calendar example and I would like to do the same thing but create a week calendar using list of datetime data as a source.

Hi Markus,
As a first suggestion try removing the quotes around the appVars.calSelectedDay.
So your formula should be something like this:

SET_DATETIME_COMPONENT(appVars.calSelectedDay, 13, "date")

*If you place the appVars… into quotes the formula editor considers it a text or string, that may be causing the issue.

I don’t really get the point of what do you wish to achieve with the weekdays. Could you elaborate more on the final function of the feature?

2 Likes

It worked. It takes while to get to know how new platform works. What I really want to do is create a week calendar:
weekCalendargif

I’m not sure if I can use formula to generate these days but I do have a list of objects including weekDay field. Somehow I just need to figure out how to generate list of days.

Hi!

@Mihaly_Toth is right about you needing to remove the “” around the appVars to get it to work.

As for the weekdays, depends kind of what you want? You can get the weekday from a date via formula FORMAT_DATETIME_LOCAL(your_date_time, "E"). This gives you a number from 0-6 based on which you know which weekday it is. Or you can get the weekday name by using FORMAT_DATETIME_LOCAL with "ddd". See more here. Or you can just populate a page/app variable with set page/app variable with the names you want to show.

1 Like

I want to create a list of weekdays (date format) so it can be repeated in 7 columns.

@Mevi I don’t know if you have a better idea how to do this but I do need a bit of guidance here how this form should look like?

First I get the selectedDay’s “ddd”

If it’s “Mon”

Then I generate list of weekdays:
SUBTRACT_DURATION(“selectedDate”, 0, “days”)
SUBTRACT_DURATION(“selectedDate”, -1, “days”)
SUBTRACT_DURATION(“selectedDate”, -2, “days”)
SUBTRACT_DURATION(“selectedDate”, -3, “days”)
SUBTRACT_DURATION(“selectedDate”, -4, “days”)
SUBTRACT_DURATION(“selectedDate”, -5, “days”)
SUBTRACT_DURATION(“selectedDate”, -6, “days”)
SUBTRACT_DURATION(“selectedDate”, -7, “days”)

If it’s “Tue”

Then I generate list of weekdays:
SUBTRACT_DURATION(“selectedDate”, 1, “days”)
SUBTRACT_DURATION(“selectedDate”, 0, “days”)
SUBTRACT_DURATION(“selectedDate”, -1, “days”)
SUBTRACT_DURATION(“selectedDate”, -2, “days”)
SUBTRACT_DURATION(“selectedDate”, -3, “days”)
SUBTRACT_DURATION(“selectedDate”, -4, “days”)
SUBTRACT_DURATION(“selectedDate”, -5, “days”)
SUBTRACT_DURATION(“selectedDate”, -6, “days”)

There might be easier way to do this too…

So I tried to create what I considered would fit your needs based on the screenvideo above. Also I have moved this issue to a new topic, to keep it clean and helpful for the future. ;D
Check it here:

Hmm, interesting puzzle! This reads like a programming challenge in school :smiley:

So you have a selectedDay and you’d like to get a list of texts/Objects with the whole week the selectedDay is in.

I would do the following: create a separate page variable for firstDayOfWeek or similar, to which you always calculate the first day of the week from the selectedDate. The exact formula depends on what you want as first day of the week – I will assume from your example you’d like it to be Monday, and this formula is based on that. To understand how the formula works, know that FORMAT_DATETIME_LOCAL("selectedDate", "E") gets the index of the weekday, where Sunday is 0.

IF(FORMAT_DATETIME_LOCAL("selectedDate", "E")>0, ADD_DURATION("selectedDate", FORMAT_DATETIME_LOCAL("selectedDate", "E")-1, "days"), ADD_DURATION("selectedDate",6,"days")) (you may have to check my math, this might be off by one in some direction)

After that the list of dates can be generated via something like MAP(GENERATE_RANGE(0,6), ADD_DURATION(pageVars.firstDayOfWeek, item, "days")).

1 Like