• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
14

Field calculations of a calibration form

Explorer ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

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;}
}

TOPICS
JavaScript , PDF , PDF forms

Views

509

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 02, 2023 Nov 02, 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
...

Votes

Translate

Translate
Community Expert ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

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;}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

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 😞

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

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 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

OK so here's where i'm at...i got the script to do what i want, but the only thing that's not working is if i delete the "as found" field, i want the "as left" field to also be blank and transparent.  Code is below.  Any idea why it's not working? It's keeping the previous value and color.

var v = Number(event.value);
var al = this.getField("VAC 1");

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

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;
al.value = event.value;
al.fillColor = color.green;
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

Try that:

var v=Nombre(event.value) ;
var al=this.getField("VAC 1") ;
event.target.fillColor=color.transparent ;
al.fillColor=color.transparent ;
al.value="" ;
if (v) {
	if (v<7.462 || v>7.538) event.target.fillColor=color.yellow ;
	else {
		event.target.fillColor=color.green ;
		al.value=event.value ;
		al.fillColor=color.vert ;
	}
}

... but in a previous message, didn't you mention "... it will allow the user to type in the calibrated result so that the "as left" field turns green."?

Where do you place your script?

Where are fields "as found" and "as left"?

@+

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

Yes, the idea would be that if the "as found" field is populated with a number that is within the range that's provided in the script, the "as left" would just be a copy of the "as found".  In this case, no user input is required in the "as found".  But if the "as found" isn't within the range, a user input would be required in the "as left".  So there would be a script in each field, as found and as left.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

Here's a section of what i'm working with.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

LATEST

Hi,

If you wish I tell you how it is possible to add an overwriting number when needed, please let me know the field name for "as found" in your example screenshot.

Capture d’écran 2023-11-03 à 21.02.38.png

With your previous screenshot, I guess the "as left" field is "VAC 1"!

... and if possible, what is the calcutation for finding the "as found" field?

@+

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

 I didn't read until the end...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

Thanks for letting me know!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

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...

@+

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines