Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Summing values using javascript and getting error "Cannot read property 'getValue' of null"

(0) ShareShare
ReportReport
Posted on by 50

Hello!

I have 7 currency value fields displayed on the opportunity form that I need rolled up into the Potential Rollup currency field. Using the javascript below I'm receiving an error of: "Cannot read property 'getValue' of null". Whether I have a value in one of the fields or not it continues to give me the error and subsequently cannot get a rollup of values in the potential rollup field. 

function CalculateValues() {
var sumRollup=
Xrm.Page.getAttribute("sone_Value1").getValue() +
Xrm.Page.getAttribute("sone_Value2").getValue() +
Xrm.Page.getAttribute("sone_Value3").getValue() +
Xrm.Page.getAttribute("sone_Value4").getValue() +
Xrm.Page.getAttribute("sone_Value5").getValue() +
Xrm.Page.getAttribute("sone_Value6").getValue() +
Xrm.Page.getAttribute("sone_Value7").getValue();
Xrm.Page.getAttribute("sone_PotentialRollup").setValue(sumRollup);
}

I have also tried this script, and it returns the same error.

function CalculateValues() {

 

   var value1 = Xrm.Page.getAttribute("sone_Value1").getValue();

 

   var value2 = Xrm.Page.getAttribute("sone_Value2").getValue();

 

   var value3 = Xrm.Page.getAttribute("sone_Value3").getValue();

 

   var value4 = Xrm.Page.getAttribute("sone_Value4").getValue();

 

   var value5 = Xrm.Page.getAttribute("sone_Value5").getValue();

 

   var value6 = Xrm.Page.getAttribute("sone_Value6").getValue();

 

   var value7 = Xrm.Page.getAttribute("sone_Value7").getValue();

 

   var sumRollup = value1 + value2 + value3 + value4 + value5 + value6 + value7;

 

   // alert(sumRollup);

 

   Xrm.Page.getAttribute("sone_PotentialRollup").setValue(sumRollup);

 

}

Any recommendations or insights would be greatly appreciated. 

I was recently solving this using a business rule, but it started creating an incremental loop rather than just summing the values. 

  • SarahC Profile Picture
    SarahC 50 on at
    RE: Summing values using javascript and getting error "Cannot read property 'getValue' of null"

    Thank you! That was exactly my issue. I was using the schema name, such a small minor fix, but made all the difference and significantly easier than the previous business rule.

  • Verified answer
    Charan Raju C R Profile Picture
    Charan Raju C R 7 Super User 2024 Season 1 on at
    RE: Summing values using javascript and getting error "Cannot read property 'getValue' of null"

    Hi Sarah,

    1. Check if all the fields (7+1) are placed on the form
    2. Verify the field names are correct. Also ensure the fields' logical names are used, not schema names in the javascript
    3. Debug javascript to identify which line or which field retrieval causing the error

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,476 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans