0

adding many record references

Is there a way to update multiple references at one time when linking two tables? I have thousands of records and it would take too long to go through them one by one.

6 replies

null
    • Fred
    • 3 yrs ago
    • Reported - view

    Hi Tom -

     

    Maybe you can give us some background first. What are the two table names? What field in tableA is now being converted to a reference field to tableB? Then we can mock something up.

    • John_Halls
    • 3 yrs ago
    • Reported - view

    Lovely progression to some succinct code Sean

     

    for oneRec in select OneTable do
    for manyRec in select ManyTable where Text = oneRec.Text do
    manyRec.(OneTable := oneRec.Id)
    end
    end

     

    Dare I say it could even be written as

     

    for oneRec in select OneTable do
    for manyRec in select ManyTable where Text = oneRec.Text
    manyRec.(OneTable := oneRec.Id)
    end

     

    Regards John

    • Sean
    • 3 yrs ago
    • Reported - view

    Thank you John.

     

    Yes, one can and the formula editor will add the missing "do" and "end"

     

    Regards Sean

    • John_Halls
    • 3 yrs ago
    • Reported - view

    Ah Sean you are right I took it from the manual which gives the example

     

    for p in (select Person)
    p.Haircolor := "red"

     

    and thought there were two forms, one that looped through one by one and another that did a bulk update but would this do it?

     

    for oneRec in select OneTable do
    let manyRec := select ManyTable where Text = oneRec.Text
    manyRec.(OneTable := oneRec.Id)
    end

     

    Regards John

    • Sean
    • 3 yrs ago
    • Reported - view

    Yes John, it works in my testing. Nicely done! Now the code is even more succinct.

     

    Regards Sean

Content aside

  • 3 yrs agoLast active
  • 6Replies
  • 666Views