0

The problem of writing N:1 code.

 Hi there, I have two tables, (HOME & copy), both contain an option named 'Y&N'. I want to set up a button that will copy the selection status of 'Y&N' in the 'copy' table to the corresponding 'Y&N' option in the 'HOME' table. How should I write the code? Thank you for your response.

7 replies

null
    • gold_cat
    • 7 mths ago
    • Reported - view
    • Fred
    • 7 mths ago
    • Reported - view

    I'm guessing that copy is the N and HOME is the 1?

    How do you want to handle when you have multiple records in copy that is linked to 1 HOME.

    This is the big question. Since you can have multiple link records Ninox needs to know which one you want to copy.

      • gold_cat
      • 7 mths ago
      • Reported - view

       Fred, who is meticulous. Currently, there is only one associated record. I will manually remove any excess records. First, I need to address the issue of copying this single associated record.

      • Fred
      • 7 mths ago
      • Reported - view

      if you only will have 1 linked record then you can use the first() command.

      'Y/N' := first(copy.'Y/N')
      
      • gold_cat
      • 7 mths ago
      • Reported - view

       

      The issue lies here. I want to change the Y&N status of all “home” at once.

      • Fred
      • 7 mths ago
      • Reported - view

      so you will need a for loop. Remember a previous post of yours where we went over for loops. Take a look at it and try to come up with the code. Even if you get an error, post it and we can go over it.

      • gold_cat
      • 7 mths ago
      • Reported - view

       

      for loop1 in select HOME do
          loop1.('Y&N' := first(loop1.copy.'Y&N'))
      end
      

      Thank you, Fred. I initially attempted it as well, but I ended up using 'for ... from ....to....' and got the wrong answer. Regardless, I managed to resolve the issue. 

Content aside

  • Status Answered
  • 7 mths agoLast active
  • 7Replies
  • 50Views
  • 2 Following