0

copy table record with child records to another table record also with child records

I want top copy a "quote" record that has child lines "quotelines' into a new table record "multiJob"  that will also have the copied records "Joblines".

but I am not quite getting the script right (or ninox is mis behaving)

lines 1 to 5 works as stand alone code as creates the parent record etc.

but adding the copy/create child records tripping me up = and i cant quite see what i am doing wrong

so any pointers would deffo be useful (it is bound to be a silly thing!)

copy from - quote record

Quote (parent) quotelines (child records)

into Jobs record

Multijobs (parent) JobLines(child records)

 

let source := this; copy Quote into 'source' variable
let tgt := (create MultiJobs);  create tgt variable fro parent record
tgt.(Customers := source.'Acc Link'); copy the stored account info in quote relationship into multijobs relasonship field
tgt.('Quote Ref' := source.'QteNum'); copy the quote numnnet into quote ref filed in new record
tgt.(Status := 1); and set status to a new job

for li in source.QuoteLines do loop to copy all sub child records
let newLI := create JobLines create the new sublines
newLI.(MultiJobs := tgt); link new child lines to parent record

write the line field info

newLI.(
        Qty := li.Qty; etc etc forr all fields rerquired to store info from quotes/childlines 

       )
end

18 replies

null
    • John_Halls
    • 2 days ago
    • Reported - view

    Hi Mel

    Just quickly There’s no semi-colon at the end of line 8

    Regards John

      • Mel_Charles
      • 2 days ago
      • Reported - view

       Hi John

       

      yes - I know i removed it to try but with a semi colon on end of line 8 that lines then also flags up a as red error too ?  😩

      • Ninox partner
      • RoSoft_Steven.1
      • 2 days ago
      • Reported - view

       what is the name of your table JobLines? Maybe you renamed this in the form but you need the tablename...(or vice versa) 

      • Mel_Charles
      • 2 days ago
      • Reported - view

        ah Yesy I had referenced the view name not the actual child name

      .

    • Fred
    • 2 days ago
    • Reported - view

    what if you delete 9 - 12 and just see if the create line works.

    can you post a sample db?

      • Mel_Charles
      • 2 days ago
      • Reported - view

       now done name coorecrtion and if i remove 9-12 it works....

      just left with this one error now?

       

    • Mel_Charles
    • 2 days ago
    • Reported - view

    deffo parent Quotes (for the  'this' part) and child table is QuoteLines

    other table is deffo MultiJobs and child is JobLines

    • John_Halls
    • 2 days ago
    • Reported - view

    I re-created your tables and the code is fine

    let source := this;
    let tgt := (create MultiJobs);
    tgt.(Customers := source.'Acc Link');
    tgt.('Quote Ref' := source.QteNum);
    tgt.(Status := 1);
    for li in source.QuoteLines do
        let newLI := (create JobLines);
        newLI.(MultiJobs := tgt);
        newLI.(Qty := li.Qty)
    end

    Not only that, but it works too

    Regards John

      • Mel_Charles
      • 2 days ago
      • Reported - view

       Hmmm

      i copied your script and still getting line 8 error.....

      some minor error on my part i nned to track down then...

      need a coffee now as getting brain fade !!! 😀

    • John_Halls
    • 2 days ago
    • Reported - view

    Multijobs vs MultiJobs ?

      • Mel_Charles
      • 2 days ago
      • Reported - view

      ?

      • John_Halls
      • 2 days ago
      • Reported - view

       One has an uppercase J MultiJobs, but in your reply earlier you said 'deffo Multijobs' which is lower case j. Line 2 is the table but line 8 is the reference and if you named the table Multijobs and later changed it to MultiJobs the reference will still be lowercase j.

      Regards John

      • Mel_Charles
      • 2 days ago
      • Reported - view

      Sorry John that was a typo from in the reply deffo Uppercase J.

       

       i can't see a miss reference to a lower case - but will take a deeper look in the morning now...

      • John_Halls
      • 2 days ago
      • Reported - view

       in your screenshot, your table is JobLines but the reference is Joblines. Have you done the same thing on the other side of the relationship, where the table is called MultiJobs but the reference is called Multjobs?

      • Mel_Charles
      • 2 days ago
      • Reported - view

       ah saw that ! and fixed that one. can;'t issue on the other ref but still have error - so done a drastically cut down copy DB - striiped out loads so will show some reference errors to tables that will no longer exist. The button is on the quote form called "test copy to multiform" you will need to copy in your script cos i can't save it with an error!

      • Fred
      • yesterday
      • Reported - view

       Look at the reference field name in JobLines to MultiJobs. You need to match the reference field name (line 9) not the table name. Unlike in create(), where you have to match the Table name not the reference field name.

      let source := this;
      let tgt := (create MultiJobs);
      tgt.(Customers:= source.'Acc Link');
      tgt.('Quote Ref' := source.QteNum);
      tgt.(Status := 1);
      for li in QuoteLines do
          let newLI := (create JobLines);
          newLI.(
              Multi_Job_TEST := tgt;
              Qty := li.Qty
          );
      end
      • John_Halls
      • yesterday
      • Reported - view

      Well done Fred. That's the one

       Regards John

    • Mel_Charles
    • yesterday
    • Reported - view

    Hi Fred/John/Stephen

    I woke up this morning to find you have proved a solution.

    Fred copied your script striaght in to button and hey presto it works.

    so THANK YOU BOTH!

    However I want to understand exactly where i had gone wrong here ( as was not sure where have i got Mutli-Job-Test? named. so

    cup of coffee and a crwal thriugh and found it.

    in earlier testing i must of called it this  and snice renaned the table but forgot to do this

     so firstly - i got confused between talking about this and view names! - Yes - feel very stupid now!

    secondly - i need to learn to step back and check and recheck again!

    if i was a tenth as good as you good then i guess i would be very good indeed!.

    I am going the leab[ve this thread open as i have another tsck durectly connect to this one. in so far as i want to be able to select just some of the child lines to copy over! (Wow!). I have a basic idea of how this can be done using a yes/no tick box on each sub line and the line(s) of script i nned to amend. but i will have a go and post it back here in a few days

    So don't rush to tell me the asnwer until it get stuck ! (which i bound be do ha ha )

    😄

Content aside

  • yesterdayLast active
  • 18Replies
  • 18Views
  • 4 Following