1

What I'm attempting to do is add an HTML button that will trigger as really simple javascript function. Essentially onclick, I want to see if a field contains a value of 0.00 - if so remove that value. Or, if the field does not contain data, add in the value of 0.00 so it should alternate between those two values.

    <html>
    <head>
    </head>
    <body>
    <button onclick="ReCalc">Re-Calculate Balance</button>
      <script>
      function ReCalc() {
        var BalanceWriteOff = Xrm.Page.getAttribute("jucy_balancewriteoff").getValue();
        if ((BalanceWriteOff) ==null)
          Xrm.Page.getAttribute("balancewriteoff").setValue("0");
          Xrm.Page.data.entity.save();
        if ((BalanceWriteOff) =="0")
          Xrm.Page.getAttribute("jucy_balancewriteoff").setValue(null);
          Xrm.Page.data.entity.save();
            return;
    }
    </script>
    </body>
    </html>   

When I try to run this on the form where the HTML element has been placed. Nothing is happening. I've thrown in some break points at the var and both if statements and I'm not getting a break when I'm triggering the onclick event.

I'm kind of stumped here. If anyone has any insights for me that would be awesome

2 Answers 2

2

Oops! In your onclick attribute you forgot to invoke the method.

To fix this, simply change onclick="ReCalc" to onclick="ReCalc()".

Here's a code pen to show you it works now - https://codepen.io/trentrand/pen/Jyomgr

Sign up to request clarification or add additional context in comments.

1 Comment

Absolutely. If you felt my answer solved the core problem described in your original post, please mark it as accepted so others in the future may refer to it as the solution.
1

To access CRM form fields from an HTML web resource, add this script to the HTML:

<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>

and prepend "parent" to the Xrm.Page object:

parent.Xrm.Page.getAttribute("jucy_balancewriteoff").getValue();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.