0

There must be a better way...

I have the following code:

let curRider := 'Team Membership'.RiderID;
let rndJmp := RiderResults.'Round Type';
let x := for loop1 in rndJmp do
        AllResultRecIDs[RiderID != curRider and 'Round Type' = loop1]
    end;
let y := replace(concat(x), ", ", ",");
let n := split(y, ",");
for loop2 in n do
    record(Results,number(loop2))
end

So at line 3 variable "x", I'm getting the following results:

rid([[2847,2848],[2880,2882],[2898,2900]])

So I can't use the result to filter, so then I have to convert "x" into a string without the grouping. Which lead me down to path that I did.

If you do a concat(x) then you get:

2847,2848, 2880,2882, 2898,2900

So on line 6, I use the replace() command to remove the space after the comma.

Then on line 7, I convert the string back into an array.

Then find the records again.

Is there a better way without having to lose the rid in line 3?

12 replies

null
    • Ninox partner
    • RoSoft_Steven.1
    • 4 mths ago
    • Reported - view

    What is AllResultRecIDs ? Is this a global function?

      • Fred
      • 4 mths ago
      • Reported - view

      It is a filter of a reference field:

      let t := this;
      Location.Results[TeamID = t.TeamIDatEvent]
      

      So it returns recId from the Results table. I want to keep the rid info but the loop command at line 3, returns grouped rid so I can't use the results directly.

    • Sean
    • 4 mths ago
    • Reported - view

    I didn't know you could create a multidimensional array in Ninox. I can't assign [[2847,2848],[2880,2882],[2898,2900]] to a variable so I can't run any operations on it.

    I don't know if the array() function would work or would be an improvement. Something like array(item(x,0),item(x,1)).

    • Alain_Fontaine
    • 4 mths ago
    • Reported - view

    The fact that a "for" loop can magically create an array is very useful in many situations, but sometimes, as in this case, it can not give the desired result. An alternative way to produce the desired array could be something like:
     

    let result := slice(AllResultRecIDs,0,0);
    for loop1 in rndJmp do
            result := array(result,AllResultRecIDs[RiderID != curRider and 'Round Type' = loop1])
     end;
    result
    
      • Sean
      • 4 mths ago
      • Reported - view

       I am very interested in this. Would you mind posting your test db?

      • Alain_Fontaine
      • 4 mths ago
      • Reported - view

       Just the minimum to show the concept…

    • Alain_Fontaine
    • 4 mths ago
    • Reported - view

    I don’t have a copy of your database to fully verify this, but could not:

    AllResultRecIDs[RiderID != curRider and contains(rndJmp,'Round Type')]
    

    replace the explicit loop ?

      • Fred
      • 4 mths ago
      • Reported - view

      What do you know. That works great! Thanks. I knew there were smarter people out there. Loves to you all!

    • Fred
    • 4 mths ago
    • Reported - view

    This more of what is happening. See the uploaded DB and look at the field Formula in Table1.

      • Alain_Fontaine
      • 4 mths ago
      • Reported - view

       Is it supposed to be a surprise? Using the same technique should give the same kind of result. Try replacing the loop by:

      let x := Table2[Text != rider and contains(rndJmp, 'Text 2')];
      
      • Fred
      • 4 mths ago
      • Reported - view

      I uploaded the DB before I rediscovered your comment below.

      Thanks again.

    • Sean
    • 4 mths ago
    • Reported - view

    Thanks for posting your example databases.

Content aside

  • Status Answered
  • 4 mths agoLast active
  • 12Replies
  • 141Views
  • 4 Following