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)

How to multiply 2 fields together and put the answer in a separate field?

(0) ShareShare
ReportReport
Posted on by 26

I need a way to multiply 2 fields together and then put the answer in another field.  I have Field A, which consists of a drop down of Yes, No, TBD.  I then have another field(B) that is a text field, but has a number in it.

If Yes is selected, then the calculation should be 1 * 100.  If No, TBD or the field is blank, then the calculation should be 0 * 100.  The answer should then be place in Field C

Then going on from that my next field (Field D) is a drop down with options from 1-10.  I would need to get the value of the selection and times that by the value in Field E and then place the answer in Field F.

I can't do a calculated field through the Form, because of the option set.  So I think I have to use a JavaScript, just not sure how to do this.  Any help is appreciated.  Thank you.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Shaminderpal Singh Profile Picture
    1,565 on at

    Hi ,

    You can achieve this by following:

    Register this function -on change of A&B

    function calculatevaluesAB() {

    var fieldA = Xrm.Page.getAttribute('a').getText();
    var fieldB = Xrm.Page.getAttribute('b').getValue();

    if (fieldA !== null && fieldB !== null) {
    var calculationOfAandB = fieldA === 'yes' ? 1 * parseInt(fieldB) : 0;
    Xrm.Page.getAttribute('c').setValue(calculationOfAandB);
    }


    }

    Register this function -on change of D &E

    function calculatevaluesDE() {
    var fielD = Xrm.Page.getAttribute('d').getText();
    var fieldE = Xrm.Page.getAttribute('e').getValue();

    if (fielD !== null && fieldE !== null) {
    var calculationOfDandE = parseInt(fielD) * parseInt(fieldE)
    Xrm.Page.getAttribute('f').setValue(calculationOfDandF);
    }
    }

    -Shaminder

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    Is there any reason why field B is a text field? Can this not be changed to a number field so you can use it with the calculated field?

    Have you also considered creating an additional field say "X" which will be used together with the other calculated field. The value in this field X will be used to save the value from field B.

  • USA80 Profile Picture
    26 on at

    I am open to all options.  What is the best method and how can I do it?  

  • USA80 Profile Picture
    26 on at

    I did the below but it isn't setting the answer at all.

    function calculatevaluesforClaimswithcostdata()

    {

    var ClaimsWithCostData = Xrm.Page.getAttribute("nhs_claimswithcostdata").getText();

    var ClaimsWithCostDataWeighting = Xrm.Page.getAttribute("nhs_claimswithcostdataweighting").getValue();

    if (ClaimsWithCostData !== null && ClaimsWithCostDataWeighting !== null)

    {

    var calculationOfClaimsWithCostDataandClaimsWithCostDataWeighting = ClaimsWithCostData === 'yes' ? 1 * parseInt(ClaimsWithCostDataWeighting) : 0;

    Xrm.Page.getAttribute("nhs_claimswithcostdataweight").setValue("calculationOfClaimsWithCostDataandClaimsWithCostDataWeighting");

    }

    }

    function calculatevaluesforHowImportantis100PassThrough()

    {

    var HowImportantIs100PassThrough = Xrm.Page.getAttribute("nhs_howimportantis100passthrough").getText();

    var HowImportantIs100PassThroughWeighting = Xrm.Page.getAttribute("nhs_howimportantis100passthroughweighting").getValue();

    if (HowImportantIs100PassThrough !== null && HowImportantIs100PassThroughWeighting !== null)

    {

    var calculationOfHowImportantIs100PassThroughandHowImportantIs100PassThroughWeighting = parseInt("HowImportantIs100PassThrough") * parseInt("HowImportantIs100PassThroughWeighting")

    Xrm.Page.getAttribute("nhs_howimportantis100passthroughweight").setValue("calculationOfHowImportantIs100PassThroughandHowImportantIs100PassThroughWeighting");

    }

    }

  • Shaminderpal Singh Profile Picture
    1,565 on at

    Did you register  function one on fields a , b both and function two on d,e ?

  • USA80 Profile Picture
    26 on at

    Yes I did

  • USA80 Profile Picture
    26 on at

    I am also getting an error that says, "Unable to get property 'setValue' of undefined or null reference at calculatevaluesforHowImportantis100PassThrough"

    Then the next error is the same but for calculatevaluesforClaimswithcostdata

  • USA80 Profile Picture
    26 on at

    When I do F12, it shows that it is grabbing the values correctly, what isn't happening is the setting of the answer field.  During F12 when it gets to the spot to do the calculation and set the field to the answer it shows a NaN

  • USA80 Profile Picture
    26 on at

    2018_2D00_06_2D00_08-11_5F00_16_5F00_42_2D00_F12.png

  • Shaminderpal Singh Profile Picture
    1,565 on at

    Do you have both fields added on the form ,we usually get this error if the fields are not present on form

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