Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Yes Basically
Copy link to clipboard
Copied
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");
Copy link to clipboard
Copied
So it looks like this would check and make it blank but not do the math that I also want performed. So the first cell if you will would allow a input of a number, The to order would do the math and subtract the numbers and give the correct answer to order. I really don't need the alert part.
I am not a programer and am only self taught so I am learning slowly and trying to figure stuff out on my own. Thanks for you help I do appreciate it.
Copy link to clipboard
Copied
You should do that in a separate calculation script.
If you don't want the alert just remove that line of code.