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 365 | Integration, Dataverse...
Answered

Create a business rule to calculate sum of the currency values in est. Total volume field in opportunity

(0) ShareShare
ReportReport
Posted on by 20

Hi all

i created 3 custom fields for Opportunity entity(Volume 1,Volume 2,Volume 3) when am giving 3 values in those fields total volumes should be calculate in est.revenue field....its working...below image 2

but when am giving only 2 fields values then again its adding 3rd field value in est.revenue field...below image 3

i want to calculate on particular given fields value only....how to do?

please suggest me....

thank you in advance5670.er-1.PNG2318.er-2.PNG4201.er-3.PNG

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    It is not adding when you are giving only 2 fields value. It s retaining previous value.

    When you try on new record and only provide 2 field value it will not be calculated.

    You can else condition in your business rule to clear the field value when condition is not ment.

    If found helpful, Please mark my answer verified.

  • Verified answer
    LuHao Profile Picture
    40,892 on at

    Hi partner,

    You can use JavaScrip to achieve it, since business rule can’t perform as well as you want.

    I try to use business rule to test, but they all failed unfortunately.

    Firstly, I new a business rule include all conditions and actions, however, it only does part of the job, and it doesn't work when I just fill in a field value.

    Then I tried to split it into multiple business processes, but executed only one of them.

    When only two fields are calculated, the business rule works perfectly, but if there are more than two fields, the business rule no longer applies.

    So JS code maybe a better choice for it.

    Here are steps.

    1. JS code.

    function sumofcurrency(executionContext) {
        var formContext = executionContext.getFormContext();
    
        var volume1 = formContext.getAttribute("new_volume").getValue();
        var volume2 = formContext.getAttribute("new_volume2").getValue();
        var volume3 = formContext.getAttribute("new_volume3").getValue();
        var test =0;
        if(volume1 !== null)
        {
         test =test   volume1;
         if(volume2 !== null)
         {
            test =test volume2;
         }
        if(volume3!== null)
        {
            test =test volume3;
        }     
        }
        else if(volume2!== null)
        {
            test=test  volume2;
            if(volume3!== null)
            {
                test =test volume3;
            }
        } 
        else if(volume3!== null)
        {
           test =test volume3;
        } 
        Xrm.Page.getAttribute("estimatedvalue").setValue(test);
    }

    2. Add your JavaScript code in a Script web resource.

    41236.png

    3. Add a OnChange event with this Script web resource to the opportunity entity form.

    (1) open the form and click Form Porperties.

    6562.png

    (2) click Add button to add JS that you create just now.

    5102.png

    (3) select these three fields and Onchange event, then click Add button to add JS.

    8637.png

    (4) double-clcik the JS and set as following.

    57148.png

    4.Test.

    02543.png

    08406.png

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 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 46 Most Valuable Professional

#2
Pallavi Phade Profile Picture

Pallavi Phade 33

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 28 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans