Expand my Community achievements bar.

SOLVED

Restricting a number to a positive value

Avatar

Former Community Member

Is there a way to restrict a number field to a positive value?

For example; a-b=c where both a and b have to be positive numbers and c cannot be less than 0.

K

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

The script looks ok. I have used Javascript so in the script editor make sure that you have the language dropdown select JavaScript and not FormCalc.

Niall

View solution in original post

4 Replies

Avatar

Level 10

Hi,

You could test the result first and then set the value of ObjectC.

The following would be in the calculate event of ObjectC:

var vResult = ObjectA.rawValue - ObjectB.rawValue

if (vResult <= 0)

{

     this.rawValue = "0"; //or = "Error" or whatever you want

}

else

{

     this.rawValue = vResult;

}

Hope that helps,

Niall

Avatar

Former Community Member

Hi Niall,

Thank you for your reply.

I tried this:

var

vResult = Qty1.rawValue - Qty2.rawValue

if

(vResult <= 0)

{

this.rawValue

= "0"; //or = "Error" or whatever you want

}

else

{

this.rawValue

= vResult;

}

and I am getting a script error on the first {

Qty1 and Qty2 are the field names for ObjectA and Object B.

K

Avatar

Correct answer by
Level 10

Hi,

The script looks ok. I have used Javascript so in the script editor make sure that you have the language dropdown select JavaScript and not FormCalc.

Niall