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

Pass or Fail condition - what if cell is blank?

Explorer ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

I have a rule for a product to pass or fail to be used.

The rule is if >30, then the product is failed and if <= 30, the product is passed.

 

I have the following script that works well.

 

var pf1 = this.getField("Product").value
if (Number(pf1)<=30){event.value = "Pass";}

if (Number(pf1)>30){event.value = "Fail";}

 

However, when I leave the cell unfilled, then the default of this product is set as "Pass" and I don't want this. I want the default setting as "" (blank) when the cell does not contain any number. 

 

Anyone can help me with this? Cheers

TOPICS
How to , JavaScript , PDF forms

Views

389

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 , Jan 18, 2023 Jan 18, 2023

You can use like this:

var pf1 = Number(this.getField("Product").valueAsString);
if(pf1){
 if(pf1<=30)
 event.value = "Pass";
 else
 event.value = "Fail";}
else
event.value = "";

Votes

Translate

Translate
Community Expert ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

You can use like this:

var pf1 = Number(this.getField("Product").valueAsString);
if(pf1){
 if(pf1<=30)
 event.value = "Pass";
 else
 event.value = "Fail";}
else
event.value = "";

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 ,
Jan 19, 2023 Jan 19, 2023

Copy link to clipboard

Copied

LATEST

Thanks heaps! This works perfectly.

 

Can you explain what is the purpose of the first if(pf1){  

 

if(pf1){ if(pf1<=30)
 event.value = "Pass";
 else
 event.value = "Fail";}
else
event.value = "";

  

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 ,
Jan 19, 2023 Jan 19, 2023

Copy link to clipboard

Copied

Can the value of the cell be zero?

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