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

How to either remake my drop box or remove duplicates?

New Here ,
Oct 24, 2024 Oct 24, 2024

Copy link to clipboard

Copied

Currently I have a set of six text fields that randomly generate a number. Lets call the A1, A2, A3, A4, A5, and A6.


I have a drop down menu where I want to populate with options based off the values of the text fields. 

 

Option A will always be present. Option B is only present if A1 or A4 is above 10. Option C is only present if A2 or A6 is above 10. Option D is only present if A3 is above 10. Option E is only available if A5 is above 10. 

 

The way I have it setup now will create doubles if A1 and A4 are both above 10 or Option C if A2/A6 are above the threshold.

 

var cDrop = ["-Select-", "Option A"];

var fields = ["A1", "A2", "A3", "A4", "A5", "A6"];

var drop = ["Option B", "Option C", "Option D", "Option B", "Option E", "Option C"];

for (var j = 0; j<fields.length; j++) {

if (Number.this.getField(fields[j].valueAsString) >=  10) {

cDrop.push(drop[j]);}}

 

this.getField("Dropdown Menu").setItems(cDrop);

TOPICS
JavaScript

Views

174

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 ,
Oct 24, 2024 Oct 24, 2024

Copy link to clipboard

Copied

Replace your last line with this script:

 

function removeDuplicates(arr) {
return arr.filter((item,
index) => arr.indexOf(item) === index);
}

this.getField("Dropdown Menu").setItems(removeDuplicates(cDrop));

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 ,
Oct 24, 2024 Oct 24, 2024

Copy link to clipboard

Copied

He will still have error because how he access field value,

I tried to simplify it for him in my script, but if he wants to use your addition he needs to change his script:
Updated script:

var cDrop = ["-Select-", "Option A"];

var fields = ["A1", "A2", "A3", "A4", "A5", "A6"];
var drop = ["Option B", "Option C", "Option D", "Option B", "Option E", "Option C"];

for (var j = 0; j < fields.length; j++) {
 var fieldValue = Number(this.getField(fields[j]).valueAsString);
 if (fieldValue >= 10) {
  cDrop.push(drop[j]);}}

//PDF Automation Station, addition to script
function removeDuplicates(arr) {
return arr.filter((item,
index) => arr.indexOf(item) === index);
}

this.getField("Dropdown Menu").setItems(removeDuplicates(cDrop));

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 ,
Oct 24, 2024 Oct 24, 2024

Copy link to clipboard

Copied

I posted to replace the last line, not the entire 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
Enthusiast ,
Oct 24, 2024 Oct 24, 2024

Copy link to clipboard

Copied

@PDF Automation Station, but what is the point of your script if it's still wouldn't work?

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 ,
Oct 24, 2024 Oct 24, 2024

Copy link to clipboard

Copied

IT DOES WORK.  When you replace the last line of @Bob30398752ze5c 's script with my script, as I said, you get @Nesa Nurani  's script, and it works.  I said to replace the last line, not the entire 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
Enthusiast ,
Oct 24, 2024 Oct 24, 2024

Copy link to clipboard

Copied

@PDF Automation StationThat is not true, there is difference between original script and Nesa's script,

in the original script, this line is a problem:
if (Number.this.getField(fields[j].valueAsString) >= 10) {

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 ,
Oct 24, 2024 Oct 24, 2024

Copy link to clipboard

Copied

I apologize.  I never tested the original script.  I assumed it was working, but adding duplicates, as stated by @Bob30398752ze5c , so I simply added a filter to remove the duplicates from the array before setting the dropdown items.

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 ,
Oct 24, 2024 Oct 24, 2024

Copy link to clipboard

Copied

Try like this:

var cDrop = ["-Select-", "Option A"];

var A1 = Number(this.getField("A1").valueAsString);
var A2 = Number(this.getField("A2").valueAsString);
var A3 = Number(this.getField("A3").valueAsString);
var A4 = Number(this.getField("A4").valueAsString);
var A5 = Number(this.getField("A5").valueAsString);
var A6 = Number(this.getField("A6").valueAsString);

if (A1 > 10 || A4 > 10) {
 cDrop.push("Option B");}

if (A2 > 10 || A6 > 10) {
 cDrop.push("Option C");}

if (A3 > 10) {
 cDrop.push("Option D");}

if (A5 > 10) {
 cDrop.push("Option E");}

this.getField("Dropdown Menu").setItems(cDrop);

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
New Here ,
Oct 25, 2024 Oct 25, 2024

Copy link to clipboard

Copied

LATEST

Thank you all! It works!!

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