0

Button Formula - Duplicate Record + sub-records

Hi all

 

I've got the formula almost down-pat to duplicate a record:

 

let reply := dialog("", "Do you wish to revise this BLA?", ["Yes", "No"]);
if reply = "Yes" then
let currRec := this.Id;
let i := (create 'BLA Form');

i.('10. BLA' := currRec.'10. BLA');
i.(Version := currRec.Version + 1);
i.(Type := Type);
i.(Requestor := currRec.Requestor);
i.('Order Date' := currRec.'Order Date');
i.('Customer Contact' := currRec.'Customer Contact');
i.('Customer PO' := currRec.'Customer PO');
i.('Payment Terms' := currRec.'Payment Terms');
i.('Multiple Delivery Locations' := currRec.'Multiple Delivery Locations');
i.('Delivery Address 1' := currRec.'Delivery Address 1');
i.('Delivery Address 2' := currRec.'Delivery Address 1');
i.('Delivery Contact 1' := currRec.'Delivery Contact 1');
i.('Delivery Contact 2' := currRec.'Delivery Contact 2');
i.('Delivery (1) Notes' := currRec.'Delivery (1) Notes');
i.('Delivery (2) Notes' := currRec.'Delivery (2) Notes');
i.('Req. Delivery Date' := currRec.'Req. Delivery Date');
i.('Shipping Terms' := currRec.'Shipping Terms');
i.(Incoterm := currRec.Incoterm);
i.(Freight := currRec.Freight);
i.('Freight Type' := currRec.'Freight Type');
i.('Container Size' := currRec.'Container Size');
i.(Product := currRec.Product);
i.('Product Type' := currRec.'Product Type');
i.('Shipping Cost (USD)' := currRec.'Shipping Cost (USD)');
i.(Specification := currRec.Specification);
i.(Packaging := currRec.Packaging);
i.(Comments := currRec.Comments);

popupRecord(i)

end

 

However, this table has 2 composition tables which I also need to duplicate the records for. To add to that, only one of the 2 composition tables will have records, depending on a choice field selected. This is where I'm currently at with playing around with the formula:

 

let reply := dialog("", "Do you wish to revise this BLA?", ["Yes", "No"]);
if reply = "Yes" then
let currRec := this.Id;
let i := (create 'BLA Form');

i.('10. BLA' := currRec.'10. BLA');
i.(Version := currRec.Version + 1);
i.(Type := Type);
i.(Requestor := currRec.Requestor);
i.('Order Date' := currRec.'Order Date');
i.('Customer Contact' := currRec.'Customer Contact');
i.('Customer PO' := currRec.'Customer PO');
i.('Payment Terms' := currRec.'Payment Terms');
i.('Multiple Delivery Locations' := currRec.'Multiple Delivery Locations');
i.('Delivery Address 1' := currRec.'Delivery Address 1');
i.('Delivery Address 2' := currRec.'Delivery Address 1');
i.('Delivery Contact 1' := currRec.'Delivery Contact 1');
i.('Delivery Contact 2' := currRec.'Delivery Contact 2');
i.('Delivery (1) Notes' := currRec.'Delivery (1) Notes');
i.('Delivery (2) Notes' := currRec.'Delivery (2) Notes');
i.('Req. Delivery Date' := currRec.'Req. Delivery Date');
i.('Shipping Terms' := currRec.'Shipping Terms');
i.(Incoterm := currRec.Incoterm);
i.(Freight := currRec.Freight);
i.('Freight Type' := currRec.'Freight Type');
i.('Container Size' := currRec.'Container Size');
i.(Product := currRec.Product);
i.('Product Type' := currRec.'Product Type');
i.('Shipping Cost (USD)' := currRec.'Shipping Cost (USD)');
i.(Specification := currRec.Specification);
i.(Packaging := currRec.Packaging);
i.(Comments := currRec.Comments);

let samRec := Samples.Id;
let y := (create Samples);

for a in currRec.Samples do

a.(y.'BLA Form' := currRec);
a.(y.Name := Name);

end;

popupRecord(i)
end

 

I may well figure it out before anyone replies - if I do I'll post my results. Until that possible outcome though - HALP D;

6 replies

null
    • SECOS Group
    • quartz_cap
    • 5 yrs ago
    • Reported - view

    Figured it out!

    Here's the final formula:

    let reply := dialog("", "Do you wish to revise this BLA?", ["Yes", "No"]);
    if reply = "Yes" then
    let currRec := this.Id;
    let i := (create 'BLA Form');
    i.('10. BLA' := currRec.'10. BLA');
    i.(Version := currRec.Version + 1);
    i.(Type := Type);
    i.(Requestor := currRec.Requestor);
    i.('Order Date' := currRec.'Order Date');
    i.('Customer Contact' := currRec.'Customer Contact');
    i.('Customer PO' := currRec.'Customer PO');
    i.('Payment Terms' := currRec.'Payment Terms');
    i.('Multiple Delivery Locations' := currRec.'Multiple Delivery Locations');
    i.('Delivery Address 1' := currRec.'Delivery Address 1');
    i.('Delivery Address 2' := currRec.'Delivery Address 1');
    i.('Delivery Contact 1' := currRec.'Delivery Contact 1');
    i.('Delivery Contact 2' := currRec.'Delivery Contact 2');
    i.('Delivery (1) Notes' := currRec.'Delivery (1) Notes');
    i.('Delivery (2) Notes' := currRec.'Delivery (2) Notes');
    i.('Req. Delivery Date' := currRec.'Req. Delivery Date');
    i.('Shipping Terms' := currRec.'Shipping Terms');
    i.(Incoterm := currRec.Incoterm);
    i.(Freight := currRec.Freight);
    i.('Freight Type' := currRec.'Freight Type');
    i.('Container Size' := currRec.'Container Size');
    i.(Product := currRec.Product);
    i.('Product Type' := currRec.'Product Type');
    i.('Shipping Cost (USD)' := currRec.'Shipping Cost (USD)');
    i.(Specification := currRec.Specification);
    i.(Packaging := currRec.Packaging);
    i.(Comments := currRec.Comments);
    for j in select Samples where 'BLA Form' = currRec do
    let h := (create Samples);
    h.(Name := j.Name);
    h.(Description := j.Description);
    h.(Qty := j.Qty);
    h.(Unit := j.Unit);
    h.('Unit Weight (kg)' := j.'Unit Weight (kg)');
    h.('Unit Price (USD)' := j.'Unit Price (USD)');
    h.('BLA Form' := i)
    end;
    for t in select Products where 'BLA Form' = currRec do
    let q := (create Products);
    q.(Products := t.Products);
    q.('QTY (rolls)' := t.'QTY (rolls)');
    q.(QTY := t.QTY);
    q.(Unit := t.Unit);
    q.('Bag Price (USD)' := t.'Bag Price (USD)');
    q.('QTY (kg)' := t.'QTY (kg)');
    q.('Price/kg (USD)' := t.'Price/kg (USD)');
    q.('Price/Roll (USD)' := t.'Price/Roll (USD)');
    q.('Roll Weight (kg)' := t.'Roll Weight (kg)');
    q.(Comment := t.Comment);
    q.('BLA Form' := i)
    end;
    popupRecord(i)
    end

    • Sean
    • 5 yrs ago
    • Reported - view

    Hi Sarah, you could reduce the whole "i" section to "duplicate(this)" if you wanted. 

    • SECOS Group
    • quartz_cap
    • 5 yrs ago
    • Reported - view

    Hi Sean

    Could you elaborate a little more? I've tried a couple of variations of replacing the i section with duplicate(this) and I haven't figured out the correct way yet... 

    • Sean
    • 5 yrs ago
    • Reported - view

    duplicate(this) will create a new record with all the data from the current record. Did you try this...

     

    let reply := dialog("", "Do you wish to revise this BLA?", ["Yes", "No"]);
    if reply = "Yes" then
    let currRec := this.Id;
    duplicate(this);
    for j in select Samples where 'BLA Form' = currRec do
    let h := (create Samples);
    h.(Name := j.Name);
    h.(Description := j.Description);
    h.(Qty := j.Qty);
    h.(Unit := j.Unit);
    h.('Unit Weight (kg)' := j.'Unit Weight (kg)');
    h.('Unit Price (USD)' := j.'Unit Price (USD)');
    h.('BLA Form' := i)
    end;
    for t in select Products where 'BLA Form' = currRec do
    let q := (create Products);
    q.(Products := t.Products);
    q.('QTY (rolls)' := t.'QTY (rolls)');
    q.(QTY := t.QTY);
    q.(Unit := t.Unit);
    q.('Bag Price (USD)' := t.'Bag Price (USD)');
    q.('QTY (kg)' := t.'QTY (kg)');
    q.('Price/kg (USD)' := t.'Price/kg (USD)');
    q.('Price/Roll (USD)' := t.'Price/Roll (USD)');
    q.('Roll Weight (kg)' := t.'Roll Weight (kg)');
    q.(Comment := t.Comment);
    q.('BLA Form' := i)
    end;
    popupRecord(i)
    end

    • Sean
    • 5 yrs ago
    • Reported - view

    Ok, I apologize. I overlooked the linking in the following...

     

    h.('BLA Form' := i)

    q.('BLA Form' := i)

     

    There might be a way to do it using duplicate(this), but I'm winding down for the day. I hope I didn't cause you too much trouble!

    • Sean
    • 5 yrs ago
    • Reported - view

    I know I tested this before I posted and now I remember how it worked. Following your example, you would use...

     

    let i := duplicate(this)

Content aside

  • 5 yrs agoLast active
  • 6Replies
  • 1725Views