Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Business Central forum

Adding values into an Array

(0) ShareShare
ReportReport
Posted on by 358

On an Item Card Page, there is a selection of Item Category which has a Code field.

I want to print that value for each of the Items selected in the Sales Quote page (Subform, line items area)

So in Sales Quote I have selected 2 items;

1) Front Hub

2) Bicycle 

and these two items have a Item Category Code set (lets say Chair, Desk respectively) in their Item Card Page. I will print Chair / Desk in the report of Sales Quote.

I am approaching this be first finding Item Category Codes for the Line Items and then putting them in a variable, then I will compare and move distinct ones (reason for finding distinct is if 2 items have same Item Category Codes I have to print that Code ONLY once,  so if 3 Line Items have Desk, Desk, Chair, I will print on the report Desk / Chair) into another array then concatenate the values with ' / ' into a Text Variable. 

Here is what I have done so far but got stuck in getting right values into my array.

On the OnAfterGetRecord Trigger of my Sales Quote Report 

I have written;

                            ItemCateTableRec.Reset();
                            ItemCateTableRec.SetFilter(Code, "Sales Line"."Item Category Code");
                            IF ItemCateTableRec.FindSet then begin
                                repeat
                                    myArray[i] := ItemCateTableRec.Code;
                                    i := i + 1;
                                until ItemCateTableRec.Next = 0;
                            end;

upon printing the myArray[1] and [2] I do not get the correct Item Category Code Chair or my Item FrontHub and Desk for my Item Bicycle. I get incorrect values.

Thanks a ton in advance for any guidance.

  • Suggested answer
    Suresh Kulla Profile Picture
    47,789 on at
    RE: Adding values into an Array

    You added the code in the OnPostDataItem which executes at the end, you need to add that in the OnAfterGetRecord of the Salesheader.

  • mysamza Profile Picture
    358 on at
    RE: Adding values into an Array

    Hello Suresh,

    I solved the issue using the following method.

    trigger OnPostDataItem()

                   var

                       sourcei: Integer;

                       filteredi: Integer;

                       intcount: Integer;

                       sourcelistcount: Integer;

                       filteredlistcount: Integer;

                       temp: Text[100];

                   begin

                       sourcei := 1;

                       filteredi := 1;

                       intcount := 1;

                       sourcelistcount := sourcelist.Count();

                       filteredlistcount := filteredlist.Count();

                       filteredlist.Insert(filteredi, sourcelist.Get(sourcei));

                       sourcei := sourcei + 1;

                       for intcount := 1 to sourcelistcount do begin

                           IF (sourcelist.Get(sourcei) <> filteredlist.get(filteredi)) then begin

                               filteredi := filteredi + 1;

                               filteredlist.Insert(filteredi, sourcelist.Get(sourcei));

                           end

                           else

                               sourcei := sourcei + 1;

                       end;

                       Clear(filteredi);

                       Clear(FilteredIC);

                       filteredi := 1;

                       intcount := 1;

                       foreach temp in filteredlist do

                           FilteredIC := FilteredIC + ' / ' + temp;

                       ItemCategoryCombined := DelStr(FilteredIC, 1, 3);

                       Message(ItemCategoryCombined);

                   end;

    I get precisely what I want to print by the variable ItemCategoryCombined.

    However, my Sales Quote has 2 dataitems, Sales Header and Sales Line. Adding the Column(ItemCategoryCombined; ItemCategoryCombined) in Sales Line doesn't print the value in the report (rdl).

    Any hint what am I missing?

  • Suggested answer
    Suresh Kulla Profile Picture
    47,789 on at
    RE: Adding values into an Array

    Where are you planning to print all Item Category codes?  I am hoping the ItemCateTableRec is temporary if not why are you checking in that table?

    You can store all the Item Category codes in a temporary table and add that to the table only if it does not exist, then loop that table to print, why do you need to store in an array.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans