| Docs Help
  AppSource  
Docs  /  NVXGRL General Report Library  /  Libraries

General Report Library [GRLGeneralReportLibraryNVX]


2023/10/09 • 13 min. to read
The codeunit contains general purpose functions

General functions

Procedure nameDescription
GetCompanyName(var CompanyInformation: Record "Company Information"): Text Chains the company information together with a fixed comma.
GetUserInfo(var SystemCreatedByGuid: Guid; var UserName: Text; var UserTelephone: Text; var UserEmail: Text) The function uses the standard SystemCreatedBy field to provide the user information. Full name -> comes from user table Telephone number and email address -> come from the user setup table.
SetTotalLabels(var TotalInclVATText: Text; var TotalExclVATText: Text; CurrencyCode: Code[10]) Returns the predefined VAT headings. Incl VAT label 'Total %1 large', 'Total amount %1 net' Excl VAT label 'Total %1 net' , 'Total amount %1 gross' The SetTotalLabels() function in the standard "Format Document" codeunit was used as a basis.
GetTotalInclVATLabelsWithCurrencyCode(TotalInclVATText: Text; CurrencyCode: Code[10]): Text Completes and returns a custom amount label with the currency code. If the currency code is empty, the "LCY Code" of the general ledger setup is used. The label should contain the "...%1" percentage value. e.g.: TotalInclVATText -> "Total %1" or "Total including VAT %1" etc.
GetTotalExclVATLabelsWithCurrencyCode(TotalExclVATText: Text; CurrencyCode: Code[10]): Text Completes and returns a custom net amount label with the currency code. If the currency code is empty, the "LCY Code" of the general ledger setup is used. The label should contain the "...%1" percentage value. e.g.: TotalExclVATText -> "Net amount %1" or "Net total %1" etc.
SetSalesPersonPurchaser(var SalespersonPurchaser: Record "Salesperson/Purchaser"; SalesPersonPurchaseCode: Code[20]) Returns the "Salesperson/Purchaser" record.
SetPaymentTerms(var PaymentTerms: Record "Payment Terms"; PaymentTermsCode: Code[10]; LanguageCode: Code[10]) Returns the "Payment Terms" record.
SetPaymentMethod(var PaymentMethod: Record "Payment Method"; PaymentMethodCode: Code[10]; LanguageCode: Code[10]) Returns the "Payment Method" record.
SetShipmentMethod(var ShipmentMethod: Record "Shipment Method"; ShipmentMethodCode: Code[10]; LanguageCode: Code[10]) Returns the "Shipment Method" record.
SetShippingAgentAndService( var ShippingAgent: Record "Shipping Agent"; ShippingAgentCode: Code[10]; var ShippingAgentService: Record "Shipping Agent Services"; ShippingAgentServiceCode: Code[10]) Returns the following records in one command: Delivery person, delivery person mode of transport Shipping Agent, Shipping Agent Services
SetPaymentShipmentSalesPersonDocumentDetails( var PaymentTerms: Record "Payment Terms"; PaymentTermsCode: Code[10]; var PaymentMethod: Record "Payment Method"; PaymentMethodCode: Code[10]; var ShipmentMethod: Record "Shipment Method"; ShipmentMethodCode: Code[10]; var SalespersonPurchaser: Record "Salesperson/Purchaser"; SalesPersonPurchaseCode: Code[20]; LanguageCode: Code[10]) Returns the following records in one function call: Payment Terms , Payment Method, Shipment Method, Salesperson/Purchaser
GetContactEmailPhone(ContactNo: Code[20]) Result: Text Returns the contact's email address and phone number. The separator is a slash.
GetContactEmail(ContactNo: Code[20]) Result: Text Returns the email address of the contact.
GetContactPhoneContact(ContactNo: Code[20]) Result: Text The function returns the phone number of the contact.
GetFullCompanyName: Text The function returns the Name1 + Name2 of the CompanyInformation table.
GetCompanyTelephone: Text The function returns the phone number from the CompanyInformation table. Format = Phone Caption with colon + phone number
GetCompanyFax: Text The function returns the fax number from the CompanyInformation table. Format = Fax Caption with colon + fax number
GetCompanyEmail: Text The function returns the email address of the CompanyInformation table. Format = email caption with colon + email address
GetShortcutDimension1to8ValueName(ShortcutDimensionNo:Integer; DimSetID: Integer): Text The function returns the selected dimension value of the dimension entry. ShortcutDimensionNo = "Shortcut Dimension 1 Code".."Shortcut Dimension 8 Code" from GeneralLedgerSetup
GetNextPositionNumber(LineType: Integer; LineTypeNo: Code[20]; var PosNo: Integer; var IsHidePosNo: Boolean) The function returns the next position number of the document line. With the IsHidePosNo variable you can set dynamically the position value in the layout (show or hide).
GetCompanyPostCodeCityCountryName(): Text The function returns the post code, city and country name from the CompanyInformation. Format = "PostCode City / CountryName"
GetCompanyNameAddressPostCodeCity(): Text The function returns the full company name - with slash - from the CompanyInformation. Format = "Name / Address / PostCode City / CountryName"
GetCompanyPostCodeCity(): Text The function returns the post code and city from the CompanyInformation. Format = "PostCode City"
GetFullCompanyAddressWithPipeSeparator(): Text The function returns the company address from the CompanyInformation. Format = "Address | PostCode City | CountryName"
SetCurrencyCode(var CurrencyCode: Code[10]; DefaultCurrencyCode: Code[10]) Returns the currency code as a var parameter. DefaultCurrencyCode can also be empty or filled from the report header (with the "Currency Code").
    
    add("Purchase Header")
    {
        column(CurrencyCode; CurrencyCode) { }
    }
    modify("Purchase Header")
    {
        trigger OnAfterAfterGetRecord()
        begin
            GeneralReportLibrary.SetCurrencyCode(CurrencyCode, "Purchase Header"."Currency Code");
        end;
    }
    
GetTrackingSpecification(RecordVariant: Variant; var TempTrackingSpecBuffer: Record "Tracking Specification" temporary; var TrackingSpecCount: Integer) The function collects and returns the item tracking datalines in the TempTrackingSpecBuffer variable. RecordVariant currently recognizes the following objects: "Sales Header", "Return Shipment Header", "Purchase Header", "Sales Invoice Header", "Sales Cr.Memo Header", "Sales Shipment Header" For "Return Shipment Header": the function RetrieveTrackingReturnShipment() must be built into an EventHook and executed it. Initialization:
    
    modify(Header)
    {
        trigger OnAfterAfterGetRecord()
        begin
            GeneralReportLibrary.GetTrackingSpecification(Header, TempTrackingSpecBuffer, TrackingSpecCount1);
        end;
    }

    
Processing and preparation for the RDLC layout:
    
    addbefore(AssemblyLine)
    {
        dataitem(HBRItemTrackingLine; "Integer")
        {
            DataItemTableView = SORTING(Number);

            column(TrackingSpecBufferLotNo; TempTrackingSpecBuffer."Lot No.") { }
            column(TrackingSpecBufferSerNo; TempTrackingSpecBuffer."Serial No.") { }
            column(TrackingSpecBufferQty; TempTrackingSpecBuffer."Quantity (Base)") { }
            column(TrackingSpecBufferUnitOfMeasure; TempTrackingSpecBuffer."Qty. per Unit of Measure") { }

            trigger OnPreDataItem()
            begin
                if TrackingSpecCount1 = 0 then
                    CurrReport.Break();

                TempTrackingSpecBuffer.SetCurrentKey("Source ID", "Source Type", "Source Subtype", "Source Batch Name", "Source Prod. Order Line", "Source Ref. No.");

                TempTrackingSpecBuffer.SetRange("Source Ref. No.", Line."Line No.");
                SetRange(Number, 1, TempTrackingSpecBuffer.Count());
            end;

            trigger OnAfterGetRecord()
            begin
                if Number = 1 then
                    TempTrackingSpecBuffer.FindSet()
                else
                    TempTrackingSpecBuffer.Next();
            end;
        }
    }
    
RetrieveTrackingReturnShipment(var TempTrackingSpecBuffer: Record "Tracking Specification" temporary; SourceID: Code[20]; var Found: Boolean) The procedure extends the "Item Tracking Doc. Management" codeunit and helps in collecting the item tracking lines. If this function is executed in the hook, the GetTrackingSpecification() function finds the associated "Return Shipment Header" item tracking lines.
    
    codeunit 50000 "AppEventHooksNVX"
    {
        var
            GeneralReportLibrary: Codeunit GRLGeneralReportLibraryNVX;

        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Tracking Doc. Management", 'OnRetrieveDocumentItemTracking', '', true, true)]
        local procedure "ItemTrackingDocManagement_OnRetrieveDocumentItemTracking"
        (
            var TempTrackingSpecBuffer: Record "Tracking Specification";
            SourceID: Code[20];
            var Found: Boolean;
            SourceType: Integer;
            SourceSubType: Option;
            RetrieveAsmItemTracking: Boolean
        )
        begin
            case SourceType of
                Database::"Return Shipment Header":
                    GeneralReportLibrary.RetrieveTrackingReturnShipment(TempTrackingSpecBuffer, SourceID, Found);
            end;
        end;
    }
    
IsArrayDifferentCompareArray1: array[8] of Text[100]; CompareArray2: array[8] of Text[100]) Result: Boolean The function compares two array variables.
GetSalesPerson(var SalesPerson: Record "Salesperson/Purchaser"; SalespersonCode: Code[20]) Returns the record of the "Salesperson/Purchaser" table.
PrintReportToLocalOrNetworkPrinterWithCommit(ReportId: Integer; RecIdToPrint: RecordId) In BC it is not possible (in a web client session) to print reports to an installed local or network printer. This is already possible via the job queue. The function does nothing other than print the report on the printer set up in the printer selection.
    
    report 50000 "WarehouseRegisterNVX"
    {
        Caption = 'Warehouse Register', comment = 'DEU="Lagerplatzjournal"';
        DefaultLayout = RDLC;
        RDLCLayout = './src/layout/WarehouseRegisterNVX.rdlc';
        UsageCategory = Documents;

        dataset
        {
            dataitem(Header; "Warehouse Register")
            {
                DataItemTableView = sorting("No.");
                RequestFilterFields = "No.";
            ...

            }
        ...

        }

        trigger OnPostReport()
        var
            GeneralReportLibrary: Codeunit GRLGeneralReportLibraryNVX;
        begin
            if not CurrReport.Preview then
                GeneralReportLibrary.PrintReportToLocalOrNetworkPrinterWithCommit(Report::WarehouseRegisterNVX, Header.RecordId);
        end;
    }
    
ResetTotalValues(var TotalSubTotal: Decimal; var TotalInvDiscAmount: Decimal; var TotalAmount: Decimal; var TotalAmountVAT: Decimal; var TotalAmountInclVAT: Decimal) Resets the total block values of the posted invoice layout. Indiv. Total functionality for the invoice. The procedure is related to the CalculateTotalValues() function.
ResetTotalValues(var TotalWeight: Decimal; var TotalAmount: Decimal; var TotalAmountVAT: Decimal; var TotalAmountInclVAT: Decimal) Resets the total block values of the proforma invoice. Indiv. Total functionality for the proforma invoice. The procedure is related to the CalculateTotalValuesSalesProFormaInvoice() function.
CalculateTotalValues(var SalesInvoiceLine: Record "Sales Invoice Line"; var TotalSubTotal: Decimal; var TotalInvDiscAmount: Decimal; var TotalAmount: Decimal; var TotalAmountVAT: Decimal; var TotalAmountInclVAT: Decimal) Sums up the total block values of the posted invoice layout. Indiv. Total functionality for the invoice. The procedure is related to the ResetTotalValues() function.
CalculateTotalValuesSalesProFormaInvoice(var SalesLine: Record "Sales Line"; var TotalWeight: Decimal; var TotalAmount: Decimal; var TotalAmountVAT: Decimal; var TotalAmountInclVAT: Decimal) Adds the total block values of the proforma invoice together. Indiv. Total functionality for the proforma invoice. The procedure is related to the associated ResetTotalValues() function.
GetItemLederEntryNoFilter(DocumentNo: Code[20]; DocumentType: Enum "Item Ledger Document Type"; DocumentLineNo: Integer) Result: Text The function returns a filter string of the table ItemLedgerEntry."Entry No.". Example return value = "1|25|302|..."
GetCommaSeparatedAddressArray(AddressArray: array[8] of Text[100]; Number: Code[20]): Text Lists the address array values one after the other - with a comma separator. Format = "Array[1], Array[2], Array[3], Array[4], etc." If the "Number" parameter is filled, the formatting changes and the address information is listed in brackets. Format = "Number (Array[1], Array[2], Array[3], Array[4], etc.)"
    
        add(Header)
        {
            column(CommaSeparatedSellToAddress; GeneralReportLibrary.GetCommaSeparatedAddressArray(AddressArray, Header."Sell-to Customer No.")) { }
        }

        var
            GeneralReportLibrary: Codeunit GRLGeneralReportLibraryNVX;
    
GetCountryRegionDescription(CountryRegionCode: Code[10]): Text The function returns the full name of the country. When fetching the data, the client language [Language.GetUserLanguageCode()] is will be taken.

Formatting functions - Converting to text

Procedure nameDescription
FormatDateToTextDay2Month2Year4(InputDate: Date): Text The function converts the input date to the DD.MM.YYYY format.
        
        reportextension 50000 "StandardSalesInvoiceExtNVX" extends "Standard Sales - Invoice"
        {
            RDLCLayout = './src/layout/StandardSalesInvoiceNVX.rdlc';
            dataset
            {
                add(Line)
                {
                    column(ShipmentDateCptn; GeneralReportLibrary.GetCaption(Enum::SFBCaptionLibraryNVX::ShipmentDate_Copy1)) { }
                    column(ShipmentDate; GeneralReportLibrary.FormatDateToTextDay2Month2Year4("Shipment Date")) { }
                }
            }

            var
                GeneralReportLibrary: Codeunit GRLGeneralReportLibraryNVX;
        }
        
        
FormatDateToTextDay2Month2Year2(InputDate: Date): Text The function converts the input date to the DD.MM.YY format.
FormatDateToDayMonthTextYear4(InputDate: Date): Text The function converts the input date to the DD.MonthText YYYY format.
FormatDateToXMLFormat(InputDate: Date): Text The function converts the input date to the YYYY-MM-DD format.
FormatDecimalToAmountFormat(DecimalValue: Decimal; AutoFormatExpr: Text[80]) Result: Text The function converts the decimal value to the standard AmountFormat.
    
    report 321 "Vendor - Balance to Date"
    {
        DefaultLayout = RDLC;
        ...

        column(Amt; Format(Amt, 0, AutoFormat.ResolveAutoFormat("Auto Format"::AmountFormat, CurrencyCode))) { }
        column(CurrencyCode1; CurrencyCode) { }
        ...

        trigger OnAfterGetRecord()
        begin
            ...
            if PrintAmountInLCY then begin
                Amt := "Amount (LCY)";
                CurrencyCode := '';
            end else begin
                Amt := Amount;
                CurrencyCode := "Currency Code";
            end;
            if Amt = 0 then
                CurrReport.Skip();
        end;
        ...
    }
    
FormatLineDiscountStdandardFormatWithPercent(LineDiscountPercent: Decimal; IsShowMinus: Boolean): Text The function converts the decimal value to text format - with a percent sign at the end. If the "IsShowMinus" parameter is true, the minus sign is added to the return value.
ExampleResult
FormatLineDiscountStdandardFormatWithPercent(85,false)85 %
FormatLineDiscountStdandardFormatWithPercent(76.4,false)76,4 %
FormatLineDiscountStdandardFormatWithPercent(32.456,false)32,46 %
FormatLineDiscountStdandardFormatWithPercent(45.32,true)- 45,32 %

General Caption Library

The General Caption Library consists of different enum values that return Captions for Reports.

Procedure nameDescription
GetCaption(Caption: Enum GRLGeneralCaptionLibraryNVX): Text[250] The function returns the captions as text for the Enum value.
GetCaption(Caption: Enum GRLGeneralCaptionLibraryNVX; isGetCaptionWithColon: Boolean): Text[250] The function returns the caption as text for the Enum that is given as a parameter. If the "isGetCaptionWithColon" parameter is true, the return value is returned with a colon.

Updated and expanded DSS functionality

CrLf(): Text[10] Returns the CR and LC characters.
Chr(Character: Char): Text Returns a character in text format.
AddValueToArray(var HeaderInfoArrCaption: array[12] of Text[250]; var HeaderInfoArrValue: array[12] of Text[250]; var i: Integer; Delimiter: Integer; Caption: Text; TextValue: Text) AddValueToArray() function from the DSS documents.
GetDocumentFooter(var CompanyInfoArr1: array[8] of Text[250]; var CompanyInfoArr2: array[8] of Text[250]; var CompanyInfoArr3: array[8] of Text[250]; CompanyAddress: array[8] of Text[250]; CompanyInformation: Record "Company Information"; IsFooterPictureHasValue: Boolean) Fills and returns the "CompanyInfoArray1", "CompanyInfoArray2" and "CompanyInfoArray3" arrays.
CollectDataFooter(var DataFooter: Text; CompanyInfoArr1: array[8] of Text[250]; CompanyInfoArr2: array[8] of Text[250]; CompanyInfoArr3: array[8] of Text[250]) Fills and returns the "DataFooter" array.
AppendDataValueText(var DataValueText: Text; NextValue: Text) Adds a new value (as the next line) to "DataValueText".
GetCompanyAddress(RespCenterCode: Code[10]; var ResponsibilityCenter: Record "Responsibility Center"; var CompanyInformation: Record "Company Information"; var CompanyAddress: array[8] of Text[100]) Returns the "Responsibility Center" and the "CompanyAddress" array.
GetDataFooter(var DataFooter: Text; var CompanyInformation: Record "Company Information"; RespCenterCode: Code[10]; IsFooterPictureHasValue: Boolean) Fills and returns the DataFooter text in RDLC layout format. On the RDLC side: Code.GLRSetDataFooter(Fields!DataFooter.Value, 1) Code.GLRGetDataFooter(1,1), Code.GLRGetDataFooter(2,1) ect.

Using the "Name/Value Buffer" solution

This functionality provides a dynamic solution to populate the header data. Here you have the option of defining and filling in several info blocks. The representation of the filled values on the RDLC side is possible with Tablix object.

Precedure nameDescription
PrepareNameValueBuffer(var NameValueBuffer: Record "Name/Value Buffer" temporary) Deletes or initializes the temporary buffer table.
AppendNameValueBuffer(var NameValueBuffer: Record "Name/Value Buffer" temporary; Name: Text; Value: Text; NameFontWeight: Enum GRLFontWeightNVX; ValueFontWeight: Enum GRLFontWeightNVX) Adds a new record to the "NameValueBuffer" record.
GetDefaultFontWeight() FontWeight: Enum GRLFontWeightNVX Returns the option FontWeight::Default
GetNormalFontWeight() FontWeight: Enum GRLFontWeightNVX Returns the option FontWeight::Normal
GetLightFontWeight() FontWeight: Enum GRLFontWeightNVX Returns the option FontWeight::Light
GetBoldFontWeight() FontWeight: Enum GRLFontWeightNVX Returns the option FontWeight::Bold
1. Definition of the associated "Name/Value Buffer" DataItems. With the columns *HeaderNameFontWeight and *HeaderValueFontWeight it is possible to define the FontWeight list in the Visual Studio Properties.
addafter("Header DataItem")
{
    dataitem(LeftHeader; "Name/Value Buffer")
    {
        DataItemTableView = SORTING(ID);
        UseTemporary = true;
        column(LeftHeaderName; Name) { }
        column(LeftHeaderValue; Value) { }
        column(LeftHeaderNameFontWeight; format(GRLNameFontWeightNVX)) { }
        column(LeftHeaderValueFontWeight; format(GRLValueFontWeightNVX)) { }
    }

    dataitem(RightHeader; "Name/Value Buffer")
    {
        DataItemTableView = SORTING(ID);
        UseTemporary = true;
        column(RightHeaderName; Name) { }
        column(RightHeaderValue; Value) { }
        column(RightHeaderNameFontWeight; format(GRLNameFontWeightNVX)) { }
        column(RightHeaderValueFontWeight; format(GRLValueFontWeightNVX)) { }
    }
}
2. Own function in the report for filling the buffer table:
var
    GeneralReportLibrary: Codeunit GRLGeneralReportLibraryNVX;
...

local procedure FillLeftHeader(var LeftHeader: Record "Name/Value Buffer" temporary; var Header: Record "Sales Invoice Header")
begin
    GeneralReportLibrary.PrepareNameValueBuffer(NameValueBuffer);

    GeneralReportLibrary.AppendNameValueBuffer(
        LeftHeader, Header.FieldCaption("Bill-to Customer No."), Header."Bill-to Customer No.", 
        GeneralReportLibrary.GetBoldFontWeight(), GeneralReportLibrary.GetBoldFontWeight());

    GeneralReportLibrary.AppendNameValueBuffer(
        LeftHeader, Header.FieldCaption("External Document No."), Header."External Document No.", 
        GeneralReportLibrary.GetDefaultFontWeight(), GeneralReportLibrary.GetDefaultFontWeight());

    GeneralReportLibrary.AppendNameValueBuffer(
        LeftHeader, Header.GetCustomerVATRegistrationNumberLbl(), Header.GetCustomerVATRegistrationNumber(), 
        GeneralReportLibrary.GetDefaultFontWeight(), GeneralReportLibrary.GetDefaultFontWeight());

    GeneralReportLibrary.AppendNameValueBuffer(
        LeftHeader, InvNoLbl, Header."No.", 
        GeneralReportLibrary.GetDefaultFontWeight(), GeneralReportLibrary.GetDefaultFontWeight());

    GeneralReportLibrary.AppendNameValueBuffer(
        LeftHeader, Header.FieldCaption("Order No."), Header."Order No.", 
        GeneralReportLibrary.GetDefaultFontWeight(), GeneralReportLibrary.GetDefaultFontWeight());

    GeneralReportLibrary.AppendNameValueBuffer(
        LeftHeader, Header.FieldCaption("Posting Date"), GeneralReportLibrary.FormatDateToTextDay2Month2Year4(Header."Posting Date"), 
        GeneralReportLibrary.GetDefaultFontWeight(), GeneralReportLibrary.GetDefaultFontWeight());

    GeneralReportLibrary.AppendNameValueBuffer(LeftHeader, Header.FieldCaption("Document Date"), GeneralReportLibrary.FormatDateToTextDay2Month2Year4(Header."Document Date"), GeneralReportLibrary.GetDefaultFontWeight(), GeneralReportLibrary.GetDefaultFontWeight());
    GeneralReportLibrary.AppendNameValueBuffer(LeftHeader, Header.FieldCaption("Due Date"), GeneralReportLibrary.FormatDateToTextDay2Month2Year4(Header."Due Date"), GeneralReportLibrary.GetDefaultFontWeight(), GeneralReportLibrary.GetDefaultFontWeight());
    GeneralReportLibrary.AppendNameValueBuffer(LeftHeader, PaymentTermsDescLbl, PaymentTerms.Description, GeneralReportLibrary.GetDefaultFontWeight(), GeneralReportLibrary.GetDefaultFontWeight());
    GeneralReportLibrary.AppendNameValueBuffer(LeftHeader, PaymentMethodDescLbl, PaymentMethod.Description, GeneralReportLibrary.GetDefaultFontWeight(), GeneralReportLibrary.GetDefaultFontWeight());

    ...
end;
3. Function call on the OnAfterGetRecord() trigger:
modify(Header)
{
	trigger OnAfterAfterGetRecord()
	begin
		FillLeftHeader(LeftHeader, Header);
		FillRightHeader(RightHeader, Header);

        ...
	end;
}
4. Using it in the RDLC layout:


Submit feedback for
DE|EN Imprint