List of years/months/weeks...
Hello,
I have a field with a Beginning Date and another one with the End Date.
Is it possibile to have a list of the months and a list of the years (or whatever time interval) that those two dates define?
Like so:
Beginning date: 01/09/2022
End date: 30/06/2023
List of Months: September 2023, October 2022, November 2022, December 2022, January 2023, February 2023, March 2023, April 2023, May 2023, June 2023.
List of years: 2022, 2023
31 replies
-
With something this large and complicated, I would first figure out which case is not working (0 or 1). Then break down each step in another formula to make sure each step works.
Here are some thoughts:
let cntYear := year(DataFinale) - year(DataAssunzione); (other code) switch cntYear do case = 0: for loop1 in range(0, cntYear) do
Maybe it is me but doesn't this say that the range is from 0 to 0? You are switching on cntYear and if case = 0 then run this loop which is from range(0, cntYear) with cntYear = 0?
for loop1 in range(0, cntYear) do let loopY := srtYear + loop1; let newRec := (create Organico); switch srtMonth do case < 9: switch endMonth do case < 9: newRec.(code...) default: newRec.(code...) default: newRec.(code...)
I think you have to move your srtMonth and endMonth variable to inside the loop or Ninox will use the data from the record you are running the script from, since it is outside of the loop. Looking at your code, I could be wrong, but most of your variables will need to be in the loop so it can gather the correct data from each record in the loop.
Also, I've found that to do less than in a switch you have to do:
switch true do case endMonth < 9: (code)
See this post for more info.
-
Gianluca said:
Let's say that I need to write:
"blue" when the range of the loop is (0,1)
"red" when the range of the loop is (1,2)
"yellow" when the range of the loop is (2, Variable)
and all this records have all to be created when I click the button.
How can I tell Ninox to do that?So to do this you would need to use a field that has the value you need to evaluate. Instead of
"blue" when the range of the loop is (0,1)
you would say:
switch true do case endMonth <9: switch fieldX do case value1: for loop in range (0,1) case value2: for loop in range (1,2) case value 3: for loop in range (2,variable1) end end end
Look at this post for information on what I did in line 1.
What you wrote is three for loop statements that will run consecutively. This is an outline of what you wrote:
switch endMonth do case < 9: for loop1 code end; for loop1 code end; for loop1 code end end
As you can see you did not put any evaluation code that would select the correct for loop to run.
I would simplify your code to first test that you are evaluating each switch properly so you would remove the for loop statements and just use simple text to test the evaluation process. Then add in more code as you validate each step.
-
Gianluca said:
What I need, instead, is that each of those loops create records in the destination table.Thanks for the clarification.
So my first question: are all of your switches evaluating as expected?
switch cntYear do: case 0: let newRec... switch srtMonth do: case < 9: switch endMonth do: case < 9: code default: code end default: switch endMonth do: case < 9: code default: code end end case 1: default: end
Second question is: do the for loops by themselves do what you need to do?
May I recommend, in the future, that you start a new post for these new questions.
Content aside
- 2 yrs agoLast active
- 31Replies
- 511Views
-
4
Following