Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Business Central

Posted on by 200

This is my requirement:

The list of Reason codes need to expand dynamically based on the Reason Codes that have been used during

the time period. If no Reason Code is selected it should show at the end in a column called Other.

This is my code:

 procedure itemjournal()

    var

        rec_Item: Record Item;

        rec_ItemJournal: Record "Item Journal Line";

        enum_EntryType: Enum "Item Journal Entry Type";

        rec_valueEntry: Record "Value Entry";

    begin

        rec_valueEntry.SetRange("Posting Date", Today - 31, Today);

        if rec_valueEntry.FindSet() then

            repeat

                if (rec_valueEntry."Item Ledger Entry Type" = enum_EntryType::"Negative Adjmt.") or (rec_valueEntry."Item Ledger Entry Type" = enum_EntryType::"Positive Adjmt.") then begin

                    rec_Item.SetRange("No.", rec_valueEntry."Item No.");

                    // Message('%1', rec_valueEntry);

                    InsertIntoTable(rec_valueEntry, rec_Item);

                end;

            until rec_valueEntry.Next() = 0;

    end;

    procedure InsertIntoTable(rec_valueEntry: Record "Value Entry"; rec_Item: Record Item)

    var

        rec_itemjournalsummary: Record ItemJournalSummary;

        enum_EntryType: Enum "Item Journal Entry Type";

    begin

        rec_itemjournalsummary.Init();

        rec_itemjournalsummary."Item Code" := rec_valueEntry."Item No.";

        rec_itemjournalsummary."Item Description" := rec_valueEntry.Description;

        rec_itemjournalsummary."Reason Code" := rec_valueEntry."Reason Code";

        if rec_valueEntry."Item Ledger Entry Type" = enum_EntryType::"Positive Adjmt." then begin

            rec_itemjournalsummary."QTY In" := rec_valueEntry."Item Ledger Entry Quantity";

            rec_itemjournalsummary."QTY Out" := 0;

        end

        else begin

            if rec_valueEntry."Item Ledger Entry Type" = enum_EntryType::"Negative Adjmt." then begin

                rec_itemjournalsummary."QTY In" := 0;

                rec_itemjournalsummary."QTY Out" := rec_valueEntry."Item Ledger Entry Quantity";

            end

            else begin

                rec_itemjournalsummary."QTY In" := 0;

                rec_itemjournalsummary."QTY Out" := 0;

            end;

        end;

        rec_itemjournalsummary.Insert(true);

    end;

    procedure SendEmail()

    var

        cdu_EmailMessage: Codeunit "Email Message";

        cdu_Email: Codeunit Email;

        ToRecipients: Text;

        Subject: Text;

        Body: Text;

        rec_ItemJournalSummary: Record ItemJournalSummary;

        rec_Valueeentry: Record "Value Entry";

        enum_Alerts: Enum Alerts;

        total: Decimal;

        total2: Decimal;

        r, c, i, j : Integer;

        rows, columns : Integer;

        reason: RecordRef;

        reasonCode: Record "Reason Code";

        reasonCodeCount, counts : Integer;

        enum_EntryType: Enum "Item Journal Entry Type";

        flag: Boolean;

    begin

        Subject := 'Item Journal Summary';

        Body += '<style>table, th, td {border:1px solid #999999;border-collapse: collapse;text-align:left;}th{padding:5px;background:#ccc;}td{padding:5px;}div{font-family: Calibri;}</style>';

        // Body += '<style>table, td, th {border: 1px solid #595959;border-collapse: collapse;}td, th {padding: 3px;width: 30px;height: 25px;}th {background: #f0e6cc;}.even {background: #fbf8f0;}.odd {background: #fefcf9;}</style>';

        Body += '<div>';

        Body += '<table><tbody>';

        Body += '<tr>';

        Body += '<td colspan="2"></td>';

        if reasonCode.FindSet() then

            repeat

                Body += '<td colspan="2">' + reasonCode.Code + '</td>';

            until reasonCode.Next() = 0;

        // Body += '<th>Other</th>';

        Body += '</tr>';

        reasonCodeCount := reasonCode.Count;

        Body += '</tr>';

        Body += '<tr>';

        Body += '<td>Item Code</td>';

        Body += '<td>Item Description</td>';

        for counts := 1 to reasonCodeCount do begin

            Body += '<td>In</td>';

            Body += '<td>Out</td>';

        end;

        if rec_ItemJournalSummary.FindSet() then

            repeat

                Body += '<tr>';

                Body += STRSUBSTNO('<td>%1</td>', rec_ItemJournalSummary."Item Code");

                Body += STRSUBSTNO('<td>%1</td>', rec_ItemJournalSummary."Item Description");

                Body += STRSUBSTNO('<td>%1</td>', rec_ItemJournalSummary."QTY In");

                Body += STRSUBSTNO('<td>%1</td>', rec_ItemJournalSummary."QTY Out");

                Body += '</tr>';

                total := total + rec_ItemJournalSummary."QTY In";

                total2 := total2 + rec_ItemJournalSummary."QTY Out";

            until rec_ItemJournalSummary.Next() = 0;

        Body += '<tfoot>';

        Body += '<tr>';

        Body += '<td></td>';

        Body += '<td><b>Total<b></td>';

        Body += STRSUBSTNO('<td>%1</td>', total);

        Body += STRSUBSTNO('<td>%1</td>', total2);

        Body += '<td></td>';

        Body += '</tr>';

        Body += '</tfoot>';

        Body += '</tr>';

        Body += '</tbody>';

        Body += '</table>';

        Body += '<br><br>Kind Regards,<br><br>Business Central';

        Body += '</div>';

        cdu_EmailMessage.Create(cdu_CommonHelper.EmailSetup(enum_Alerts::"Item Journal Summary"), Subject, Body, true);

        if rec_ItemJournalSummary.Count > 0 then begin

            cdu_Email.Send(cdu_EmailMessage);

            rec_ItemJournalSummary.DeleteAll();

        end;

    end;

}

So please help in this how can I get dynamically reason code on In Out column on runtime.

Categories:
  • Suggested answer
    Andy Sather Profile Picture
    Andy Sather on at
    RE: Business Central

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    I will open this up to the community in case they have something to add.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,219 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans