web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JS Function Undefined

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Rafael Batista Profile Picture
    on at
    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 ?

  • Powell360 Profile Picture
    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?

  • Suggested answer
    Community Member Profile Picture
    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
    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
    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
    on at
    RE: JS Function Undefined

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

  • Community Member Profile Picture
    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
    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?

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans