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

26 replies

null
    • Mel_Charles
    • 22 hrs ago
    • Reported - view

    Fred - I am going to have to come back to you on this. At the moment I can't quite get my head around your suggested code and as to how that will sit in my script

    I need a quiet evening and lots of coffee to understand what yiour script is doing to make sense to me!

    your code

    let productRec := record(Products,number(Pcode)) let vFileName := item(split(productRec, "/"), 1); let vShare := shareFile(productRec.Image); ItemImage := importFile(this, vShare, vFileName); unshareFile(vTable, "vFileName")

     

    my code

    if Pcode then
        'Short Description' := record(Products,number(Pcode)).text(Category);
        Qty := record(Products,number(Pcode)).Qty;
        Description := record(Products,number(Pcode)).Description;
        CostEach := record(Products,number(Pcode)).Cost;
        SellEach := record(Products,number(Pcode)).Sell;
        Supplier := record(Products,number(Pcode)).Supplier;
        ItemImage := record(Products,number(Pcode)).ItemImage;
        Mkup := (SellEach - SubCost) / SubCost * 100;
        SellFlag := false
    else
        'Short Description' := null;
        Qty := 1;
        Description := null;
        CostEach := null;
        SellEach := null;
        Supplier := null
    end

      • Fred
      • 16 hrs ago
      • Reported - view

       try this:

      if Pcode then
          let productRec := record(Products,number(Pcode))
          'Short Description' := productRec.text(Category);
          Qty := productRec.Qty;
          Description := productRec.Description;
          CostEach := productRec.Cost;
          SellEach := productRec.Sell;
          Supplier := productRec.Supplier;
          Mkup := (SellEach - SubCost) / SubCost * 100;
          SellFlag := false;
          #code to copy image#;
          let vFileName := item(split(text(productRec.Image), "/"), 1);
          let vShare := shareFile(productRec.Image);
          ItemImage := importFile(this, vShare, vFileName);
          unshareFile(productRec, "vFileName")
      

      Line 12: I'm creating a variable (vFileName) to hold the filename of the original image so we can use it later. If you create a formula in the Products table with:

      text(Image)

      You will see a letter and a number followed by / then the filename. So we then use the split() command to divide the string at the / and then we use the item() command to grab the second grouping of text (remembering that everything starts with 0).

      Line 13: we share the item that is in the original Image field and store in a variable to be used later.

      Line 14: we can now import the image and give it a proper name using the variables we created in lines 12 and 13.

      Line 15: like the good programmers we are, we stop sharing the file by using the unshareFile() command

Content aside

  • 16 hrs agoLast active
  • 26Replies
  • 63Views
  • 4 Following