Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Unanswered

How to generate a report from "Posted Sales Shipment" only if items are part of a category?

Posted on by 73
Hello,
 
I'm extending the /Posted Sales Shipment/ page and created a button in order to generate contracts based on the /Item Category Code/. For hardware items, I generate a contract that would be different from software items.
 
My problem is that I don't know how to filter my /Sales Shipment Header/ table to know if there are hardware items in it and then generate the correct report.
 
pageextension 50125 PostedSalesShipmentExt extends /Posted Sales Shipment/
{
    actions
    {
        addlast(processing)
        {
            action(/Generate Contracts/)
            {
                ApplicationArea = Basic, Suite;
                Promoted = true;
                PromotedCategory = Category4;
                Image = Export;
 
                trigger OnAction()
                var
                    XmlParameters: Text;
                    FileMgt: Codeunit /File Management/;
                    Filename: Text;
                    TempBlob_lRec: Codeunit /Temp Blob/;
                    BlobOutStream: OutStream;
                    RecRef: RecordRef;
                    SalesShptHeader: Record /Sales Shipment Header/;
                    SalesShipmentLine: Record /Sales Shipment Line/;
                    RecLineRef: RecordRef;
                    CountLines: Integer;
                begin
                    SalesShptHeader.Reset();
                    SalesShptHeader.SetRange(/No./, Rec./No./);
                    SalesShptHeader.FindFirst();
                    SalesShipmentLine.Reset();
                    SalesShipmentLine.SetRange(/No./, Rec./No./);
                    SalesShipmentLine.SetFilter(/Item Category Code/, '1.0-COTS-HARDWARE');
                    RecLineRef.GetTable(SalesShipmentLine);
                    CountLines := RecLineRef.Count();
                    RecRef.GetTable(SalesShptHeader);
                    if (RecRef.Count() > 0) then begin
                        XmlParameters := Report.RunRequestPage(Report::PostedSalesShptContractsReport);
                        // XmlParameters := '<?xml version=/1.0/ standalone=/yes/?><ReportParameters name=/PostedSalesShptContractsReport/ id=/50125/><DataItems><DataItem name=/Header/>VERSION(1) SORTING(Field3)</DataItem><DataItem name=/Line/>VERSION(1) SORTING(Field3,Field4)</DataItem><DataItem name=/ItemTrackingLine/>VERSION(1) SORTING(Field1)</DataItem></DataItems></ReportParameters>';
                        TempBlob_lRec.CreateOutStream(BlobOutStream, TEXTENCODING::UTF8);
                        report.SaveAs(Report::PostedSalesShptContractsReport, XmlParameters, REPORTFORMAT::Pdf, BlobOutStream, RecRef);
                        Filename := Format(Rec./No./) + '.pdf';
                        FileMgt.BLOBExport(TempBlob_lRec, Filename, TRUE);
                    end;
                end;
            }
        }
    }
}
 
Any help would be greatly appreciated!
 
Thanks in advance

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!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans