Skip to main content
Participating Frequently
March 5, 2023
Question

number validation

  • March 5, 2023
  • 1 reply
  • 2021 views

I have a form to inventory supplies. I have a fillable field to tell how many is in stock. It is calculated by the current stock levels then shows how many items to order in another field. I only want to show a number if it is between 1 and the total number that is alowed to be stocked in the field. Otherwise I want it to be blank.  I have attached the form itself. The number to order field shows all calculations or the current stock levels but I want it to be blank if above or below the stock levels if that makes since. Thanks for the assistance. 

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
March 5, 2023

So you want to limit the On Hand column to a value between 1 and the value in that row's To Order value, basically?

 

Participating Frequently
March 5, 2023

Yes Basically

try67
Community Expert
Community Expert
March 6, 2023

The basic code to do that is simple, but the issue is you didn't name your field very consistently, so you would have to adjust the code for each individual set... You can use a doc-level function for generic script, and then call it from each field, like this:

 

function validateOnHand(toOrderFieldName) {
	if (event.value=="") return;
	var toOrderField = this.getField(toOrderFieldName);
	if (toOrderField==null) {
		console.println("Error! Can't find the field: " + toOrderFieldName);
		return;
	}
	var toOrderValue = Number(toOrderField.valueAsString);
	if (event.value>toOrderValue) {
		app.alert("Error! Maximum allowed value: " + toOrderValue);
		event.rc = false;
	}
}

 

And then you would call it from the Validation event of the first field in the file, for example, like this:

validateOnHand("Text1");