Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

How to find the same value from container

(1) ShareShare
ReportReport
Posted on by 171
Hi Team.
Below is container value
Container con1 = [A,B,A,A,A,A,B,A,B,B,C,B,B,C,B,D]
How to count same value from container?
Example;
A is repeating 6 time.
Output: A = 6
B is repeating 7 time.
Output: B = 7
C is repeating 2 time.
Output:  C = 2
D is 1 time.
Output:  D = 1
 
  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    How to find the same value from container
    Dear User, what should the sample code show? Do you mean that you don't know how to use Map class and you failed to find the information on internet?
     
    If so, look at Collection Classes "Map". The example there covers the same scenario as yours.
  • CU21091228-0 Profile Picture
    CU21091228-0 171 on at
    How to find the same value from container
    Hi Martin,
     
    Could you please provide the sample code?
  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    How to find the same value from container
    If we wanted to get count of all distinct values, I would use a Map object rather then involving database. The overhead of writing to database and reading from there would be too big, IMHO.
  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    How to find the same value from container
    Hi,
     
    I think without know the value in the container it's hard to get the report you wanted. 
    As code provide by the martin you need to know the value in the container to increase the counter value.
    One workaround without hardcoding will be - Creating table with string field - Loop through the container using for loop and insert the values into the table.
    Later add a while select statement with count of RecId and group by the field where you inserted the container value.
    I am not sure this will work but you can give it a try - But this is time consuming one as it requires insert record in the table and adding while select to the same table.
     
    Thanks,
    Girish S.
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    How to find the same value from container in D365FO
    You need to take values one by one and calculate what you need. If you don't know how to work with containers, the relevant documentation page (
     
    The implementation might look like this:
    int counter;
    
    for (int i = 1 ; i <= conLen(con1) ; i++)
    {
        str value = conPeek(con1, i);
        if (value == 'A')
        {
            counter++;
        }
    }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans