Skip to main content
Known Participant
November 2, 2023
Answered

Field calculations of a calibration form

  • November 2, 2023
  • 3 replies
  • 3326 views

Good morning!  I'm creating a calibration test form.  In this form, there are "as found" and "as left" columns.  In the "as found" column, i have different calculations that change the background color based on the user input and whether or not the test is successful (green) or needs additional calibration (yellow).

I'm looking for a script that will copy the "as found" field if the background is green, into the "as left" field.  And if the "as found" field is yellow, it will allow the user to type in the calibrated result so that the "as left" field turns green.  Below is a copy of the "as found" field.  Any help would be appreciated!  Hope this wasn't too confusing 😕😕  I can ellaborate more if you need 🙂

 

var v = Number(event.value);
{
if (!event.value)
{event.target.fillColor = color.transparent;}

else if (v<7.462 || v>7.538) {event.target.fillColor = color.yellow;}

else if (v>=7.462 && v<=7.538){event.target.fillColor = color.green;}
}

This topic has been closed for replies.
Correct answer Nesa Nurani

If  'green' it copies only value and if 'yellow' it only set color to green?

You can update your script to work for both fields and use it in "as found" field as 'Validation' script:

 

var v = Number(event.value);
var a = this.getField("as left");

if(!event.value){
event.target.fillColor = color.transparent;
a.fillColor = color.transparent;
a.value = "";}

else if(v<7.462 || v>7.538){
event.target.fillColor = color.yellow;
a.value = "";
a.fillColor = color.green;}

else if (v>=7.462 && v<=7.538){
event.target.fillColor = color.green;
a.value = v;}

 

 

3 replies

Known Participant
November 2, 2023

Thank you both!  I'll try them both to see how they perform.  Then end goal for me is when the calibration is good (green) it copies everything directly to the as found field, and if not, it would follow my original script.

bebarth
Community Expert
Community Expert
November 2, 2023

 I didn't read until the end...

Known Participant
November 2, 2023

Thanks for letting me know!

bebarth
Community Expert
Community Expert
November 2, 2023

Here is my proposal:

this.getField("asLeft").value="";
if (event.source && (event.source.name=="numberA" || event.source.name=="numberB")) var v=Number(this.getField("numberA").value)+Number(this.getField("numberB").value);
else var v=Number(event.value);
event.value=v;
event.target.fillColor=color.transparent;
if (v) {
	if (v<7.462 || v>7.538) {
		event.target.fillColor=color.yellow;
		event.target.readonly=false;
		this.getField("asLeft").value="";
	} else {
		event.target.fillColor=color.green;
		event.target.readonly=true;
		this.getField("asLeft").value=event.value;
	}
}

You can modify the "asFound" number if it is less than 7.462 or more than 7.538.

Let me know if this is what you wish...

@+

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
November 2, 2023

If  'green' it copies only value and if 'yellow' it only set color to green?

You can update your script to work for both fields and use it in "as found" field as 'Validation' script:

 

var v = Number(event.value);
var a = this.getField("as left");

if(!event.value){
event.target.fillColor = color.transparent;
a.fillColor = color.transparent;
a.value = "";}

else if(v<7.462 || v>7.538){
event.target.fillColor = color.yellow;
a.value = "";
a.fillColor = color.green;}

else if (v>=7.462 && v<=7.538){
event.target.fillColor = color.green;
a.value = v;}

 

 

Known Participant
November 2, 2023

Let me try to explain better:

if (!event.value)
{event.target.fillColor = color.transparent;}

else if as found background fill = green

   then copy as found background color and field value into as left field

else if (v<7.462 || v>7.538) {event.target.fillColor = color.yellow;}

else if (v>=7.462 && v<=7.538){event.target.fillColor = color.green;}

 

Ultimately, what it's saying is that when it's green, the as found and as left values are the same and acceptable.

When the "as found" is yellow, then calibration needs to be performed until it is within the provided range, at which time the "as left" value will be the value after calibration.  If calibration is performed and the acceptable range cannot be achieved, then the "as left" should remain yellow, alerting the customer that the unit is bad and needs replacement or repair.  So it's realistic to say that both fields will be yellow, although the yellows are independent of each other.

 

I'm confusing you 😞

Nesa Nurani
Community Expert
Community Expert
November 2, 2023

I'm not sure if I fully understand, but try this:

var v = Number(event.value);
var a = this.getField("as left");

if(!event.value){
event.target.fillColor = color.transparent;
a.fillColor = color.transparent;
a.value = "";}

else if(v<7.462 || v>7.538){
event.target.fillColor = color.yellow;
a.fillColor = color.yellow;}

else if (v>=7.462 && v<=7.538){
event.target.fillColor = color.green;
a.value = v;
a.fillColor = color.green;}

There is no need to compare colors since they are depended on value of a field, so you can use same script to achieve both.

If it's not correct, script has all components, you just need to order them correctly 🙂