Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Calculation of Minimum Value

Posted on by 100

Hello,

I have a scenario to calculate the minimum of 2 fields and store it in another field. (i.e) There are 2 fields, Fees owed and Grant Amount.

if fees Owed =  1999 and Grant amount = 2000, I need to find min of both of these fields and populate the minimum value in another field called "Approved grant Amount". 

(Eg)Fees Owed = 1999

Grant Amount = 2000

Approved Grant Amount = 1999 (This needs to get populate by itself when those 2 fields have value in it and this is the minimum of both fields).

Can we do this without Javascript code? or if this can be achieve only by javascript can I get sample code for it?

Many Thanks,

Poornimaa An

*This post is locked for comments

  • Poornimaa Profile Picture
    Poornimaa 100 on at
    RE: Calculation of Minimum Value

    And, thanks to everyone for the suggestions. :)

  • Poornimaa Profile Picture
    Poornimaa 100 on at
    RE: Calculation of Minimum Value

    Thank you, Ravi Kashyap. I created a field with the calculation logic and it is working fine. !! Your help is much appreciated. :)

  • Suggested answer
    Iswarya Profile Picture
    Iswarya 1,345 on at
    RE: Calculation of Minimum Value

    Hi ,

    try this

    function SetminimumValue()

    {

       debugger;

      var FeesOwed = Xrm.Page.getAttribute("new_feesowed").getValue();

      var GrantAmount = Xrm.Page.getAttribute("new_grantamount ").getValue();

      if (FeesOwed != null && GrantAmount != null)

      {

          if (FeesOwed > GrantAmount)

          {

              Xrm.Page.getAttribute("new_approvedgrantamount").setValue(GrantAmount);

          }

          else if (FeesOwed < GrantAmount)

          {

              Xrm.Page.getAttribute("new_approvedgrantamount").setValue(FeesOwed);

          }

      }

    }

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Calculation of Minimum Value

    You can probably also use a Business Rule for the situation you are looking for.

    If FeesOwed < GrantAmount

      SetValue of New Field to GrantAmount

    Else

      SetValue of New Field to FeesOwed

    See screenshot below (used Latitude fields, but logic is the same).

    1351.business_5F00_rule.png

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Calculation of Minimum Value

    Hi,

    Other option is to have Approved Grant Amount as a calculated field and have this as the calculation logic i.e. set the value which is lowest. Note that if you already have the Approved Grant Amount field created, you can use it as calculated field. for this you need to delete and recreate the field as calculated.

    If you can't delete then best option is workflows as suggested above.

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Calculation of Minimum Value

    if the fields are numeric (whole number, decimal or float) you can use a simple crm workflow (triggered on the update of the two fields)

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans