0

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

31replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
    • Fred
    • Fred
    • 3 mths ago
    • Reported - view

    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.

    Like 1
      • Gianluca
      • Gianluca
      • 3 mths ago
      • Reported - view

      Fred 

      Fred said:
      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?

       Yes, it does. I thought to keep the same "logic" used for the following steps of the formula, while building the final one, Then I would simply get rid of what is useless.

       

      Fred said:
      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

       Ok, I will try

      And thanks also for the last suggestion: brilliant!

      Like
      • Gianluca
      • Gianluca
      • 3 mths ago
      • Reported - view

      Fred I've tried, but I can't make it work.

      I think the problem is where two or more loops have to be used in order to create all the records, like in this bit of the formula:

      switch endMonth do
                          case < 9:
                              for loop1 in range(0, 1) do
                              let loopY := srtYear + loop1;
                              let newRec := (create Organico);
                              newRec.(
                              DataInizioServizio := xDataA;
                              DataFineServizio := date(srtYear, 8, 31);
                              Mansione := xMans;
                              DipendenteCdS := xNomDip;
                              Contratti := xCont);
      
                              for loop1 in range(1, 2) do
                              let loopY := srtYear + loop1;
                              let newRec := (create Organico);
                              newRec.(
                              DataInizioServizio := date(srtYear, 9, 1);
                              DataFineServizio := date(loopY, 8, 31);
                              Mansione := xMans;
                              DipendenteCdS := xNomDip;
                              Contratti := xCont);
      
                              for loop1 in range(2, cntYear) do
                              let loopY := srtYear + loop1;
                              let newRec := (create Organico);
                              newRec.(
                              DataInizioServizio := date(loopY, 9, 1);
                              DataFineServizio := date(loopY + 1, 8, 31);
                              Mansione := xMans;
                              DipendenteCdS := xNomDip;
                              Contratti := xCont);
      
                          default:
                              for loop1 in range(0, 1) do
                              let loopY := srtYear + loop1;
                              let newRec := (create Organico);
                              newRec.(
                              DataInizioServizio := xDataA;
                              DataFineServizio := date(srtYear, 8, 31);
                              Mansione := xMans;
                              DipendenteCdS := xNomDip;
                              Contratti := xCont);
      
                              for loop1 in range(1, 2) do
                              let loopY := srtYear + loop1;
                              let newRec := (create Organico);
                              newRec.(
                              DataInizioServizio := date(srtYear, 9, 1);
                              DataFineServizio := date(loopY, 8, 31);
                              Mansione := xMans;
                              DipendenteCdS := xNomDip;
                              Contratti := xCont);
      
                              for loop1 in range(1, cntYear) do
                              let loopY := srtYear + loop1;
                              let newRec := (create Organico);
                              newRec.(
                              DataInizioServizio := date(loopY, 9, 1);
                              DataFineServizio := date(loopY + 1, 8, 31);
                              Mansione := xMans;
                              DipendenteCdS := xNomDip;
                              Contratti := xCont);
                      end
      

      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?

      Like
    • Fred
    • Fred
    • 3 mths ago
    • Reported - view
    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.

    Like
    • Fred
    • Fred
    • 3 mths ago
    • Reported - view
    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.

    Like 1
      • Gianluca
      • Gianluca
      • 3 mths ago
      • Reported - view

      Fred yes sorry… I’ll start a new thread. I keep posting here because it’s an “evolution” of the original subject, but it’s going astray 😂😂😂

       might be my Italian attitude 😃

       anyway… the for loops were the ones you already suggested (just a little tweaked) and they do their job.

      But I haven’t had the chance of testing them in this new formula, cause the formula isn’t correct in some points 😁

      Like
Like Follow
  • 3 mths agoLast active
  • 31Replies
  • 211Views
  • 4 Following