0

Copy table including line items from subtable, to another table and subtable)

Hello everyone.

I am trying for a few days to get this working but am stuck. Maybe someone can point me in the right direction.

I have a table "Quote" and it has a subtable "quLineItems" where I add the line items of the quotation.
Then I have a table named "PO" for Purchase Orders. There is also a subtable in named "puLineItems".

If a customer accepts the quotation, I want to click the button "Create PO" with a script that should copy some of the fields and all but "COST" column of the line items in the quLineItems subtable to the POs table.

I can have the script create a new PO and copy some fields, but I can't get the subtable contents from "Quote" to "PO".

The code used with the button below.

let xCurrRec := Id;
let i := (create PO);
let p1 := 'Issued by';
i.(Issuer := p1);

for k in select 'quLineItems' do
k.(
let f1 := k.NO;
let f2 := k.Qty;
let f3 := k.Description;
let f4 := k.'PPU THB';

k.'Line Items'.(Qty := f2);
k.'Line Items'.(Description := f3);
k.'Line Items'.('COST' := f4);
)
end
void

But the line items aren't copied over.

Thanks for any help.

5 replies

null
    • Ninox partner
    • RoSoft_Steven.1
    • 1 yr ago
    • Reported - view

    This could help you

    let issu := 'Issued by';
    let i := (create PO);
    i.(Issuer := issu);
    for k in 'Line Items' do
        let no := k.NO;
        let qty := k.Qty;
        let desc := k.Description;
        let cost := k.'PPU THB';
        let c := (create poLineItems);
        c.(
            Qty := qty;
            Description := desc;
            COST := cost;
            PO := i
        )
    end
    

    Not sure what you want with the NO field but you can change the code to your needs.

    Steven

    • NetSol Co., Ltd.
    • Bernd_Krell
    • 1 yr ago
    • Reported - view

    Hello RoSoft_Steven

    Thank you for the reply. I had to modify the code a bit as it showed several errors. But still no line items created when copying it to a PO.
    The only thing happening is that a new PO is created and "Issued by" field is copied over.
    But no line item records are created.
    By the way, that NO field is the number field, sort order.

    Any idea why no line items are created?

     

    let i := (create PO);
    let p1 := 'Issued by';
    i.(Issuer := p1);
    for k in 'Line Items' do
        let no := k.NO;
        let qty := k.QTY;
        let desc := k.DESCRIPTION
        let cost := k.SELL;
        let c := (create poLineItems);
        c.(
            Qty := qty;
            Description := desc;
            Price := cost;
            NO := no
        )
    end
    
      • Ninox partner
      • RoSoft_Steven.1
      • 1 yr ago
      • Reported - view

      Yes, you forgot one line after NO := no (at the end of your code)

      PO := i 

      This links the new created Line Items with the new created PO

      Steven

    • NetSol Co., Ltd.
    • Bernd_Krell
    • 1 yr ago
    • Reported - view

    Thank you RoSoft_Steven but add this line brings up an error as shown in the screenshot. It thinks this is a field.

    • NetSol Co., Ltd.
    • Bernd_Krell
    • 1 yr ago
    • Reported - view

    Found it. Should be 

    'Purchase Orders' := i

    Thank you so much RoSoft_Steven for pointing me into the right direction. This was super helpful.

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 5Replies
  • 162Views
  • 2 Following