Skip to main content
Inspiring
December 19, 2021
Answered

print number of copies

  • December 19, 2021
  • 2 replies
  • 1865 views

Hi

I would like to create a function that allows me to vary the number of copies of a page to print, depending on whether or not the wording "Unemployed" is present in the "PROFESSION-2" field.
 
This is the function I created but it doesn't work

var pp = this.getPrintParams ();
pp.colorOverride = pp.constants.colorOverrides.blackandwhite;
pp.pageHandling = pp.constants.handling.fit;
pp.printRange = [[30,30]];
var s1 = this.getField ("PROFESSION-2"). value;
if (s1 == "Unemployed") {s1.value = "3";} else {s1.value = "4";}
pp.NumCopies = s1.value;
pp.DuplexType = 1;
pp.printerName = getField ("PRINTER"). value;
pp.interactive = pp.constants.interactionLevel.silent;
this.print (pp);
 
Can anyone help me please?
Correct answer qqwe_5278

Issue resolved! The function now checks the PROFESSION-2 field and sets the print copy count based on whether it contains “Unemployed.” Thanks for the help!

{Third party web link removed by Adobe Moderator}

2 replies

Participant
May 27, 2025

Hi all, I’m trying to create a function that changes the number of copies to print based on whether the word "Unemployed" appears in the PROFESSION-2 field. I wrote a function, but it’s not working as expected.

Appreciate any help! Also, feel free to check out our place:

Participant
May 27, 2025

function getPrintCopies(profession) {
if (profession.toLowerCase().includes("unemployed")) {
return 1; // Only 1 copy if unemployed
} else {
return 2; // Default to 2 copies otherwise
}
}

// Example usage
let professionField = "Unemployed Engineer";
let copies = getPrintCopies(professionField);
console.log("Number of copies to print:", copies);

try67
Community Expert
Community Expert
May 27, 2025

You have multiple errors in your code.

First of all, you used the wrong field name, as you noticed.

But you also didn't access it correctly. You need to use getField and the value (or valueAsString) properties to access a field's value.

In addition, there's no log method to console object in Acrobat. Use println, instead.

And don't use let, as that creates a constant, not a variable. Change it to var.

Plus, you're not doing anything with the value returned by the function. You should use it as an input parameter when calling the print method.

try67
Community Expert
Community Expert
December 19, 2021

Your description is a bit vague, but try this:

 

var s1 = this.getField("PROFESSION-2").valueAsString;
var matches = s1.match(/Unemployed/gi);
if (matches!=null) {
	pp.NumCopies = matches.length;
	// rest of printing code goes here
}
ENE5CD9Author
Inspiring
December 19, 2021

Hi
Yes, sorry. I didn't make myself clear. If the word "UNEMPLOYED" appears in the "PROFESSION-2" field, I want 3 copies of page 30 to be printed, otherwise I want 4 copies of page 30 to be printed

try67
Community Expert
Community Expert
December 19, 2021

Use this, then:

 

pp.printRange = [[29,29]];
var s1 = this.getField("PROFESSION-2").valueAsString;
if (/Unemployed/.test(s1)) pp.NumCopies = 3;
else pp.NumCopies = 4;