Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Change User Entered Decimal Value prior to Calculate Event?

Avatar

Level 1

Hi,

Is it possible to check a user entered value in a Decimal field and change it prior to it being used in Calculate events associated with other fields? Basically I want to trap zero and null values at source, change them to 1 and thus prevent "division by zero" errors that would have occurred in other fields on the form.

Thanks,

Rod.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Rod,

I think I must still be missing something.  I thought all errors in the calculate event were suppressed.  I hope the attached form helps explain what I suggested.

Bruce

View solution in original post

9 Replies

Avatar

Former Community Member

if (myTextBox.rawValue == 0)

{

myTextBox.rawValue = 1

}

before you do your calculations

Avatar

Level 1

Hi xrum,

Thanks for the quick reply. The issue is that the field that needs to be validated and potentially corrected is one that is referenced by multiple other fields. I did start off by doing exactly what you stated, but it just seems so inefficient to build that check into each and every calculate event that references the offending field ... there must be a way of fixing it at source before any other field potentially uses the value.

I have tried coding the check into the Validate event of the Decimal field itself, but I keep getting Value Validate Failed messages. That said, I think the Validate event fires after the Calculate event on the other fields anyway. All I need to know is which event fires before Calculate events thus giving me the opportunity to change the illegal value before any other script tries to use it.

Thanks,

Rod.

Avatar

Level 10

Hi Rod,

I think you were on the right track.  The calculate event does fire before the validate event but if the validate event updates the field then the calculate event will fire again.  So if there are no side effects of the calculate event and it does take to long to run then you could add the following into the validate event of the decimal field;

if (this.isNull || this.rawValue == 0)
{
this.rawValue = 1;
}
true;

In the validate event the result of the last statement determines if the field is valid, so you need the true there looking very un-JavaScript like.

Bruce

Avatar

Level 1

Hi Bruce,

Thanks for the reply. The problem is that there is a side effect of the Calculate event in other fields processing a null/zero value before it is changed by the Validate event on the offending field and that comes in the form of an "Error: arithmetic over/underflow" error dialog which the user then has to close before proceeding. Apparently I should be able to use the Calculate event on the offending field to trap the issue before other Calculate events fire, but I have tried numerous scripts and settings but all to no avail

Thanks,

Rod.

Avatar

Correct answer by
Level 10

Hi Rod,

I think I must still be missing something.  I thought all errors in the calculate event were suppressed.  I hope the attached form helps explain what I suggested.

Bruce

Avatar

Level 1

Thank you Bruce ... I will check out your form and report back as soon as your attachment is released from the queue.

Rod.

Avatar

Level 1

Hi Bruce,

Many thanks for your example PDF as it has highlighted an interesting issue. It turns out that our scripts were functionally identical, the only difference being that mine were written in FormCalc and yours in JavaScript. With yours there is no division by zero error reported, with mine there is! If I simply change my calculate event from FormCalc to Javascript (and add a ; at the end of the calculation line) then the zero error disappears and everything works as expected. Evidently there are some subtle differences between the two languages other than straightforward syntax. I'm beginning to think that FormCalc has "issues" and should be avoided!

Thanks again,

Rodney.

Avatar

Level 10

Glad you got it resolved, it had me a bit perplexed but didn't have time to follow it further (I was trying to help you out on the AUC forums).

I wouldn't avoid FormCalc it does some things very well, this sounds like a possible bug.

Avatar

Level 1

Another solution was to put "if([DENOMINATOR]>0)then[FORMULA]endif", in place of your formula alone.