Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

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

Posted on by 2,645

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

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to multiply 2 fields together and put the answer in a separate field?

    So things are working now.  Thank you for your help.

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to multiply 2 fields together and put the answer in a separate field?

    Here is the code that I am using:

    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_claimswithcostdatascore").setValue(calculationOfClaimsWithCostDataandClaimsWithCostDataWeighting);

    }

    }

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to multiply 2 fields together and put the answer in a separate field?

    OK, I got one of them working, now the remaining issue is the error of "Unable to get property 'setValue' of undefined or null reference at calculatvaluesforClaimswithcostdata

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to multiply 2 fields together and put the answer in a separate field?

    data type is a whole number in which the answer of the calculation should be going into this field.

  • Shaminderpal Singh Profile Picture
    Shaminderpal Singh 1,565 on at
    RE: How to multiply 2 fields together and put the answer in a separate field?

    Can you tell me the data type of field in which you are setting value?

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to multiply 2 fields together and put the answer in a separate field?

    I still get the error.  I do see though when I do F12, I now see the calculation is working correctly, but just doesn't put the answer in the field now.  Do I need quotes in the setValue last line?

  • Shaminderpal Singh Profile Picture
    Shaminderpal Singh 1,565 on at
    RE: How to multiply 2 fields together and put the answer in a separate field?

    Hi

    As I  mentioned earlier you need to remove quotes from this line as well

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

    Regards

    Shaminder

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to multiply 2 fields together and put the answer in a separate field?

    I have this now:

    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);

    }

    }

    Am I am still getting the error of "Unable to get property 'SetValue" or undefined or null reference at calculatevaluesforHowImportantis100PassThrough

    Any ideas on how to fix this?

  • Verified answer
    Shaminderpal Singh Profile Picture
    Shaminderpal Singh 1,565 on at
    RE: How to multiply 2 fields together and put the answer in a separate field?

    Just saw you are adding the variable name in quotes while setting the value,remove the quote

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

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

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

  • Shaminderpal Singh Profile Picture
    Shaminderpal Singh 1,565 on at
    RE: How to multiply 2 fields together and put the answer in a separate field?

    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans