Skip to main content
steft66579364
Known Participant
Jun 28, 2017 2:44 PM UTC
Answered

Help with positive and or negative data put into a field

Hi,

Can someone please help me , I have 10 fields which are populated with measured data.

The data can be positive or negative, but not greater than -10 or +10

If the data being measured is put into any of the fields, is less than or =  -10  / + 10 then I want to populate another field with "pass"

but if the data being put into any of the fields is greater than -10 /+10 then I want to populate the other field with "fail"

This is measured data,microns so can be positive or negative.

Many thanks

This topic is closed to new replies. Start a new post to keep the conversation going.
Karl Heinz  Kremer
Karl Heinz KremerCorrect answer
Community Expert
Jun 29, 2017 12:14 PM UTC

You would have to copy the script I provided to all eight Pass/Fail fields and then adjust the field name that is checked.

10 replies

Inspiring
Jun 28, 2017 3:53 PM UTC

Do you mean the data needs to be within  +/- 10 of a given measurement or the value needs to be between -10 and +10 .

The following script can handle either case when the correct values for the stand and the range are entered.

// get the data from the form field ;

var d = this.getField("Measurement").valueAsString;  // test field valueAsString;

if(d == "")

{

// no entry for test

event.value = "";

} else {

// report if test result within allowed range;

var nStandard = 15; // required standard;

var nRange = 10; // acceptible variance from standard;

// compute difference from a standard;

var nDiff = Math.abs(nStandard - Number(d))

event.value = (nDiff > nStandard) ? "Fail", : "Pass";

}

One could even write a custom function to indicate a pass or fail for the result when compared to a standard and a range for acceptance.

Such a function could be:

function Results(nStandard, nRange, nTestValue)
{
// function to return logical true or false if test value not within the range for the standard value;
return Math.abs(nStandard - nTestValue) <= nRange;
} // end Results function;

And the custom calculation for the individual result field could then be:


// get the data from the form field ;
var d = this.getField("Measurement").valueAsString;  // test field valueAsString;
if(d == "")
{
// no entry for test
event.value = "";
} else {
// report if test result within allowed range;
var nStandard = 15; // required standard;
var nRange = 10; // acceptible variance from standard;
// compute difference from a standard;
event.value = Results(nStandard, nRange, d) ? "Pass" : "Fail";
}

Translate
steft66579364
Known Participant
Jun 29, 2017 9:01 AM UTC

Hello gkaiseril,

really appreciate your response, forgive me if I am wrong but your answer applies to one field

I have 8 fields that all need to be between -10 micron and 10 micron.

How could I write the above the 8 different fields

See below

thank you

Stef

Translate
Karl Heinz  Kremer
Community Expert
Community Expert
Jun 28, 2017 3:04 PM UTC

You can use something like the following script as the custom calculation script for your pass/fail field:

// get the data from the form field

var d = this.getField("Data1").value;

if (d == "") {

    event.value = "";

}

else if (Math.abs(d) > 10) {

    event.value = "fail";

}

else if (Math.abs(d) <= 10) {

    event.value = "pass";

}

Translate
steft66579364
Known Participant
Jun 29, 2017 10:21 AM UTC

Hello, Karl Heinz Kremer

I tried your script for 8 fields

var h = this.getField("ValueH").value;

var g = this.getField("ValueG").value;

var f = this.getField("ValueF").value;

var e = this.getField("ValueE").value;

var d = this.getField("ValueD").value;

var b = this.getField("ValueB").value;

var a = this.getField("ValueA").value;

if(h==""&&g==""&&f==""&&e==""&&d==""&&c==""&&b==""&&a=="") {

event.value="";

}

else if (Math.abs(h,g,f,e,d,c,b,a) >  10){

event.value "Fail";

}

else if (Math.abs(h,g,f,e,d,c,b,a) < = 10) {

event.value = "Pass";

But I get an error on line 12 ; missing statement

any help please

Stef

Translate
Legend
Jun 29, 2017 11:52 AM UTC

You can't replace abs(one thing) with abs(list,of,many,things). You need separate abs for each value. You have to connect them with && (and) or || (or); think about which one is right.

Translate
Bernd Alheit
Community Expert
Community Expert
Jun 28, 2017 3:02 PM UTC

steft66579364  wrote

...

The data can be positive or negative, but not greater than -10 or +10

...

Can you explain this? Every positive number is greater than -10.

Translate