Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

JS Function Undefined

Posted on by

I have found a simple JS function to take the values of some children, sum them and set a field on my parent form with that value.

My JS is :- 

function timeout(){
setTimeout(calcCostoTotal, 3000);
}
function calcCostoTotal() {
var grid = document.getElementById(‘Services’);
var ids = grid.control.get_allRecordIds();
var sum = 0.00;
var cellValue;
for(i = 0; i < ids.length; i++) {
var cellValue = grid.control.getCellValue(iss_salesprice,ids[i]);
var number = Number(cellValue.replace(/[^0-9\.]+/g,”));
sum = sum + number;
}
Xrm.Page.data.entity.attributes.get(ava_tempgrossvalue).setValue(sum);
}


And I have added the library to the form and called calcCostoTotal OnLoad but I get an undefined error.

Services is the name of a view on the form which shows the children

iss_salesprice is the child value

ava_tempgrossvalue is the parent field

Can anyone spot my mistake? 

If this is an inappropriate approach can anyone point me in the direction of a better one please? 

Thank you in advance 

*This post is locked for comments

  • Powell360 Profile Picture
    Powell360 on at
    RE: JS Function Undefined

    Should this line "var cellValue = grid.control.getCellValue(iss_salesprice,ids[i]);" contain the name of the child field to be summed or the label under which it appears in the grid?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: JS Function Undefined

    When you adding grid to form you need to specify it name. Open form editor and find name of grid.

  • Powell360 Profile Picture
    Powell360 on at
    RE: JS Function Undefined

    I only have a view. I'd put a grid on and hide it if I knew how.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: JS Function Undefined

    'Services' is the name of view? You need to use name of grid. Try to debug you code and check that you can get your grid.

  • Powell360 Profile Picture
    Powell360 on at
    RE: JS Function Undefined

    Uriy, they are in the correct format in CRM. I can't figure out why this wont work! Is it because Services is a view on the form?

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: JS Function Undefined

    >var grid = document.getElementById(‘Services’);

    >Number(cellValue.replace(/[^0-9\.]+/g,”));

    Wrong quotation marks. Change ‘ and ” to ' or "

  • Powell360 Profile Picture
    Powell360 on at
    RE: JS Function Undefined

    The error says :-

    There was something wrong with this field's customized event.

    Field:Window

    Event:onload

    Error:'calcCostoTotal' is undefined.

    Where I have referenced the fucntion on the form load in the properties I did not include the "()" to the fucntion call. Is that correct?

  • RE: JS Function Undefined

    Hello Powell,

    Your code looks ok.

    Can you give us more details on the undefined error ? What is the log message displayed ?

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans