Auto Populate Header Field to Line table

Hi Guys

I have two tables commissionHeader and Commisionlines with a relationship just like Sales Header and Line, I have agent no. field on the header and when it is selected i wanted it also to get populated on line field and tried to copy the function from Sales Header.

TESTFIELD(“Document No.”);
IF (“Document Type” <> SalesHeader.“Document Type”) OR (“Document No.” <> SalesHeader.“No.”) THEN BEGIN
SalesHeader.GET(“Document Type”,“Document No.”);
IF SalesHeader.“Currency Code” = ‘’ THEN
Currency.InitRoundingPrecision
ELSE BEGIN
SalesHeader.TESTFIELD(“Currency Factor”);
Currency.GET(SalesHeader.“Currency Code”);
Currency.TESTFIELD(“Amount Rounding Precision”);
END;
END;

Tried to Modify it like below

TESTFIELD(“No.”);
IF (“No.” <> CommisionDocumentHeader.“Document No.”) THEN BEGIN
CommisionDocumentHeader.GET(CommisionDocumentHeader.“Document No.”);
END;

Then Called the function on pk field on validate, then tried to assign header field to the line but nothing happened

GetCommissionHeader;
“Agent No.”:= CommisionDocumentHeader.“Agent No.”;

Appreciate for your help in advance

I think you selected the wrong example. If I understood your description correctly you need to see the UpdateSalesLines function like an example.

if you need to take data from the header in line you can check your code or InitHeaderDefaults.

Hi, RedfoxUA

I am using NAV 2017, I couldn’t find a function called “UpdateSalesLines” and I tried to do this code instead and it worked manually when i click an action button when it is placed in there but when I put it on validating trigger of the subpage or subtable it is not working

CommisionDocumentLine.RESET;
CommisionDocumentLine.SETRANGE(“No.”,“Document No.”);
IF CommisionDocumentLine.FINDFIRST THEN BEGIN
REPEAT
CommisionDocumentLine.“Agent No.”:=“Agent No.”;
CommisionDocumentLine.MODIFY;
UNTIL CommisionDocumentLine.NEXT=0
END;

Any thought ?

I’m using the same and table 36 has this function “UpdateSalesLines”.

but you wrote right and it is something like:

CommisionDocumentLine.RESET;
CommisionDocumentLine.SETRANGE(“No.”,“Document No.”);
//some more filters here
IF CommisionDocumentLine.FINDSET THEN
REPEAT
CommisionDocumentLine.“Agent No.”:=“Agent No.”;
CommisionDocumentLine.MODIFY({RunTriggerValue});
UNTIL CommisionDocumentLine.NEXT=0;
or
CommisionDocumentLine.RESET;
CommisionDocumentLine.SETRANGE(“No.”,“Document No.”);
//some more filters here
CommisionDocumentLine.MODIFYALL(“Agent No.”, “Agent No.”, {RunTriggerValue});

HI There late reply, was away

I tried this code as you advised but no luck.

ComDocLine.RESET;
ComDocLine.SETRANGE(“No.”,CommisionDocumentHeader.“Document No.”);// Only filter field i have
IF ComDocLine.FINDSET THEN
REPEAT
“Posting Date”:= CommisionDocumentHeader.“Posting Date”;
“Agent No.”:= CommisionDocumentHeader.“Agent No.”;
ComDocLine.MODIFY;
UNTIL ComDocLine.NEXT=0;

ComDocLine.RESET;
ComDocLine.SETRANGE(“No.”,CommisionDocumentHeader.“Document No.”);
IF ComDocLine.FINDSET THEN
//“Agent No.”:= CommisionDocumentHeader.“Agent No.”;
ComDocLine.MODIFYALL(“Agent No.”,CommisionDocumentHeader.“Agent No.”);

I couldn’t figure out what I messed up, share your valuable suggestion. BTW I put it on ComDocLine table Product No. field onValidate trigger. needed to be populated when the user selects product no.

Thanks

I think you need to debug it because I don’t understand what does not work (this code is very simple)

Try to add ComDocLine. to your two lines in the Repeat loop. Right now it’s not updating the ComDocLine table, but the “global” rec var.

Thanks for your suggestion.Did this but no change.

ComDocLine.RESET;
ComDocLine.SETRANGE(ComDocLine.“No.”,CommisionDocumentHeader.“Document No.”);// Only filter field i have
IF ComDocLine.FINDSET THEN
REPEAT
ComDocLine.“Posting Date”:= CommisionDocumentHeader.“Posting Date”;
ComDocLine.“Agent No.”:= CommisionDocumentHeader.“Agent No.”;
ComDocLine.MODIFY;
UNTIL ComDocLine.NEXT=0;

Could you check how many time your code perform loop (it is in the line “IF ComDocLine.FINDSET THEN”)? Is the debug for it and trace step-by-step. I think you have 0 lines for the update after filtering.