Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Help with JavaScript formula

Avatar

Level 1

I am working on what I thought would be a simple formula to determine a percentage. I keep running into what I believe is a divide by 0 error. The message reads " The value entered does not match the format of the field [Meeting attendance percentage]". Because I am unframiliar with writing JavaScript I need help resolving this issue. If someone could please help with my formula I would appreciate it. I have tried changing the format from number to none and that did nto seem to fix the problem.

Here is my JavaScript

var a=this.getField("Number of meetings during period");
var b=this.getField("Number of meetings attended during period");
event.value=(b.value/a.value)

Thank you so much for your help.

1 Reply

Avatar

Level 6
Try this variation in your event.value code

var v1 = +getField("numerator").value;
var v2 = +getField("demoninator").value;

event.value = (v2 !== 0) ? (v1 / v2) : "";

This code assumes the input fields have a numeric format type. You
would replace "numerator" and "demoninator" in the code above with the
names of your fields.