0

Update all recoords

Hi there

has anyone tried to update all records in a parent table with the link to a child table ?

I have a parent table called members and a child table called photos.

 

In the child table I have two fields 1. is member number and 2. is image, and in the parent I have several fields where one is the member number corresponding to the same number in child. I have created a form where the parent shows all the fields according to my layout and a linked view to the child table, in this form I have set up a button, which only shows if the image field is empty and by trigger the button it creates the link and the button does disappear. The code in the button formula is this :

let myTable1 := Id;
let myText := Medlemsnr;
for i in (select Foto)[Medlemnr = myText] do
    i.(medlemmer := myTable1)
end

and it works perfectly, however I imagine that I could do all the records automatically instead of manually go through the whole database - for example with a global function.

Can anyone help me here ?

 

rgds

Leo

6 replies

null
    • John_Halls
    • 8 mths ago
    • Reported - view

    Hi Leo

    Yes you can create an outer loop to loop through all your members

    for j in select members do
       let myText := j.Medlemsnr;
       for i in (select Foto)[Medlemnr = myText] do
           i.(medlemmer := j)
       end
    end
    

    Change members to be the name of your members table.

    Regards John

      • Leo_Woer
      • 8 mths ago
      • Reported - view

       Thank you very much Sir - I will try it and return with result

      rgds

      Leo

    • John_Halls
    • 8 mths ago
    • Reported - view

    If your tables are large, you may wish to wrap the whole thing in a do as server

      • Leo_Woer
      • 8 mths ago
      • Reported - view

       hi John

      I took your code and corrected it so members now is medlemmer, and then I placed it in Global Functions but nothing happened. It must be because I an quite new to Ninox, so when you say outer loop what in fact do you mean ?

    • John_Halls
    • 8 mths ago
    • Reported - view

    Hi Leo

    Put the code in a button, and just run it once. It can go anywhere.

    Regards John

    • Leo_Woer
    • 8 mths ago
    • Reported - view

    Super it worked perfectly - thank you John

Content aside

  • 8 mths agoLast active
  • 6Replies
  • 73Views
  • 2 Following