web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Putting values in a table on executing custom action

(2) ShareShare
ReportReport
Posted on by 390

Hello community, 

I have created a custom action button ("Post WHT") on a custom page ("WHT Transaction"). Now I want that whenever the action is executed all the values currently present on the custom page should be appended to the payment journal new line.  Below pictures will clear this more.  In the first image, the custom action and custom page is shown and in the second image payment journal lines are shown. Now whenever I execute the action, the values from my custom page should be appended to the new line of payment journal. I tried posting this but I am getting primary key error in shown in third image. There is no primary key used in the custom table or page. Kindly help.

pastedimage1672039056746v1.png

pastedimage1672039217999v2.png

pastedimage1672039999643v3.png

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    Hi,

    Please share lines of code, so that I can see what is done and what left.

    Thanks.

  • Muhammad Anas Naeemi Profile Picture
    390 on at

    These are the lines of code. The marked (squared) field are the three primary keys of Gen. Journal Line table. I hard coded them as I don't any other way to use the primary keys for extraction of values. Kindly help. 

    pastedimage1672044180728v1.png

  • Suggested answer
    Mohana Yadav Profile Picture
    60,993 Super User 2025 Season 2 on at

    What is the Primary Key of Table "WHT Transaction Table"?

    I think the error is from 2nd line of Findset. What is the purpose of 1st and 2nd lines?

  • Muhammad Anas Naeemi Profile Picture
    390 on at

    "Code" is the primary key of "WHT Transaction table". Basically the two lines are used to get the data present in "WHT Transaction table".

  • Suggested answer
    pankaj.k Profile Picture
    994 on at

    Hi Muhammad,

    Check you line no. may be its find duplicate and if its working fine then use

    REC.Init;
    Rec."Journal Template Name":= value1;
    rec."Journal Batch Name" := Value2;
    Rec."Line No." := value3;
    Rec.insert;
    assign value  as you do.
    rec.modify;
  • Muhammad Anas Naeemi Profile Picture
    390 on at

    I'm not getting errors in line no. I'm getting for the above two fields

    pastedimage1672053032603v1.png

  • Suggested answer
    Mohana Yadav Profile Picture
    60,993 Super User 2025 Season 2 on at

    Click on the "How to report this issue" in the above error and copy to clipboard and paste here.

  • Muhammad Anas Naeemi Profile Picture
    390 on at

    The Gen. Journal Template does not exist. Identification fields and values: Name=''

    Internal session id:

    8c965386-364f-45c9-80ad-1bc7b6f70ef1

    Application Insights session id:

    da9ee9f7-01d1-4268-bb9c-b897681e7d61

    Client activity id:

    057fd3f4-512f-526e-5e9a-0c596624e974

    Timestamp:

    2022-12-26T11:50:19.6358353Z

    AL call stack:

    "Gen. Journal Line"(Table 81).OnInsert(Trigger) line 7 - Base Application by Microsoft

    "Payment Journal CodeUnit"(CodeUnit 50130).PaymentJournalLine line 16 - ThailandWHT by Default publisher

    "Payment Journal CodeUnit"(CodeUnit 50130).OnRun(Trigger) line 2 - ThailandWHT by Default publisher

    "WHT Transaction ListPlus"(Page 50103)."Action1 - OnAction"(Trigger) line 4 - ThailandWHT by Default publisher

  • Suggested answer
    pankaj.k Profile Picture
    994 on at

    Hi Muhammad,

    I am using the same code and its working fine you need to create 2 field in the sales& Rec Setup where you mention the "Journal Template Name", "Journal Batch Name" with table relation form parent table.

    insert81.PNG


    GenJnLine.Init();
    GenJnLine."Journal Template Name" := SRSetup.LoanAutoPstTemplate;
    GenJnLine."Journal Batch Name" := SRSetup.LoanAutoPstBatch;
    LineNo := GenJnLine.GetNewLineNo(SRSetup.LoanAutoPstTemplate, SRSetup.LoanAutoPstBatch);
    GenJnLine."Line No." := LineNo;
    GenJnLine."Document No." := DocNo;
    GenJnLine.Insert();
    GenJnLine.Validate("Posting Date", LoanHeader.NextDueDate);
    GenJnLine."Document Date" := LoanHeader.NextDueDate;
    case GenJnlTemplate.Type of
    GenJnlTemplate.Type::General:
    begin
    GenJnLine.Validate("Account Type", GenJnLine."Account Type"::Customer);
    GenJnLine.Validate("Account No.", LoanHeader."Customer No.");
    end;
    end;
    GenJnLine."Source Code" := GenJnlTemplate."Source Code";
    GenJnLine."Payment Method Code" := 'Bank';
    GenJnLine.Validate(GenJnLine."Account Type", GenJnLine."Account Type"::Customer);
    GenJnLine.Validate("Account No.", LoanHeader."Customer No.");
    TransactionCode.Reset();
    TransactionCode.SetRange("Type of Fee", TransactionCode."Type of Fee"::Interest);
    if (TransactionCode.FindFirst) then
    if (TransactionCode."G/L Account no" <> '') then
    GenJnLine.Validate("Bal. Account No.", TransactionCode."G/L Account no")
    ELSE
    Error('Transaction Codes for Interest fee is not Configured');
    GenJnLine.ecl_AccountNo := LoanHeader.AccountNumber;
    GenJnLine.Ecl_LoanAccountName := LoanHeader.name;
    GenJnLine.Ecl_TransactionCode := TransactionCode.Code;
    GenJnLine."Source No." := LoanHeader.AccountNumber;
    GenJnLine.Validate(Amount, ROUND(InterestAmount, 0.01, '='));
    CLosingBalance += InterestAmount;
    GenJnLine.Modify();

    Try with this it will work.

  • Muhammad Anas Naeemi Profile Picture
    390 on at

    Hey Pankaj,

    I don't get it. Can you tell me in steps what exactly I have to achieve my functionality. Moreover, my code is different from yours.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,226

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,047 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,257 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans