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...
Suggested answer

Created a Report with text fields that are populated through c/al code - SOLVED

(0) ShareShare
ReportReport
Posted on by 47

I have created a report with C/AL Code that I am using to create three fields that do not exist in NAV. The reason for the fields to be created in this way is they are needed to be a part of the .csv file that is sent to the bank. This is for positive pay situation so we can go paperless with checks. The fields as easy as it was to create and get it to populate it is causing some issues with outputting the file automatically. As I have found a post from Cloud-Fronts on how to export a csv file from a report, it does not cover the need to pass text fields that you have created. My question is this possible? The error I am getting is that in the c/al code when I save the error is 

A field from a record variable was expected. For example:

Record.Field

Customer.Name

The code that is giving the error is (This is just a snipet of the entire Code. This is where the issue throws the error. 

LOCAL MakeExcelDataHeader()
ExcelBuffer.AddColumn("Check Ledger Entry".FieldCaption("Always28"),FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuffer."Cell Type"::Text);

Full Code

OnInitReport()
PrintToExcel:=TRUE;   //ADDED FOR CREATE OF EXCELBOOK

OnPreReport()
ExcelBuffer.DELETEALL;    //ADDED FOR CREATE OF EXCELBOOK

OnPostReport()
IF PrintToExcel THEN    //ADDED FOR CREATE OF EXCELBOOK
  CreateExcelBook;

Check Ledger Entry - OnPreDataItem()
MakeExcelDataHeader;    //ADDED FOR CREATE OF EXCELBOOK 

Check Ledger Entry - OnAfterGetRecord()
"Check Ledger Entry".Description:= (DELCHR("Check Ledger Entry".Description, '=' , ','));

IF "Check Ledger Entry".Amount <> 0 THEN
  AccountNo := '267104';

IF "Check Ledger Entry"."Entry Status" = 2 THEN
  TransCode := 'VD';
IF "Check Ledger Entry"."Entry Status" = 3 THEN
  TransCode := 'IA';
IF "Check Ledger Entry"."Entry Status" = 4 THEN
  TransCode := 'VA';

Always28:= '28';

IF PrintToExcel THEN    //ADDED FOR CREATE OF EXCELBOOK
  MakeExcelDataBody;


Check Ledger Entry - OnPostDataItem()

LOCAL MakeExcelInfo()

LOCAL MakeExcelDataHeader()
ExcelBuffer.AddColumn("Check Ledger Entry".FIELDCAPTION("Check No."),FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuffer."Cell Type"::Text);    //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry".FIELDCAPTION("Check Date"),FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuffer."Cell Type"::Text);   //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry".FIELDCAPTION("Amount"),FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuffer."Cell Type"::Text);   //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry".FIELDCAPTION("Always28"),FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuffer."Cell Type"::Text);   //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry".FIELDCAPTION("AccountNo"),FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuffer."Cell Type"::Text);    //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry".FIELDCAPTION("TransCode"),FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuffer."Cell Type"::Text);    //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry".FIELDCAPTION("Description"),FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuffer."Cell Type"::Text);    //ADDED FOR CREATE OF EXCELBOOK

LOCAL MakeExcelDataBody()
ExcelBuffer.NewRow;   //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry"."Check No.",FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuffer."Cell Type"::Text);    //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry"."Check Date",FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuffer."Cell Type"::Text);   //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry"."Amount",FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuffer."Cell Type"::Text);   //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry"."Always28",FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuffer."Cell Type"::Text);   //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry"."AccountNo",FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuffer."Cell Type"::Text);    //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry"."TransCode",FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuffer."Cell Type"::Text);    //ADDED FOR CREATE OF EXCELBOOK
ExcelBuffer.AddColumn("Check Ledger Entry"."Description",FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuffer."Cell Type"::Text);    //ADDED FOR CREATE OF EXCELBOOK

LOCAL CreateExcelBook()

Report-50050.png

  • Suggested answer
    Andy Sather Profile Picture
    on at
    RE: Created a Report with text fields that are populated through c/al code

    Hello Troy- We currently do not have dedicated Dev support via the Dynamics NAV 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

    dynamicsuser.net/.../developers

    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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 715

#2
YUN ZHU Profile Picture

YUN ZHU 682 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 529

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans