web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Minimum/Maximum number of the field

(0) ShareShare
ReportReport
Posted on by

Hi, i need to get the maximum and minimum number of related products on project according to a decimal field using any help?

the below code is not setting the true max number and not setting the min value:

foreach (var RelatedProductsRecords in RelatedProductsEntity.Entities)
                    {
                        var Total= RelatedProductsRecords .GetAttributeValue<decimal>("new_totalarea");
                        log.Info("prod Size= " + Total);

                        decimal highestFound = decimal.MaxValue;
                        log.Info("highestFound= " + decimal.MaxValue);
                   
                        decimal lowestFound = decimal.MinValue;
                        log.Info("lowestFound= " + decimal.MinValue);
 
                        if (Total> highestFound)
                        {
                            highestFound = TotalCoveredArea;
                            log.Info("Maximum pro Size= " + Total);

                            ProjectEntity.Attributes["new_sizetorange"] = highestFound;
                            log.Info("product size To = " + highestFound);

                            service.Update(ProjectEntity);
    
                        }

                        if (Total< lowestFound)
                        {
                            lowestFound = Total;
                            log.Info("Minimum Apartment Size= " + Total);

                            ProjectEntity.Attributes["new_sizefromrange"] = lowestFound;
                            log.Info("product size from = " + lowestFound);

                            service.Update(ProjectEntity);
                        }
}

*This post is locked for comments

I have the same question (0)
  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    You should put the global variables (lowestFound, highestFound...) outside the for loop.

    As your code is right now they are re-instantiating every time you loop.

     

    You can also use fetchXml with aggregates to get these numbers.

    Hope this helps.

  • Community Member Profile Picture
    on at

    Hi Aric ,

    the same issue when  i was putting them outside the loop, not entering the min value and not setting the right max value

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans