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

print number of copies

Participant ,
Dec 19, 2021 Dec 19, 2021

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?
TOPICS
JavaScript
1.8K
Translate
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Dec 19, 2021 Dec 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;

View solution in original post

Translate
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 Beginner ,
May 27, 2025 May 27, 2025

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}

View solution in original post

Translate
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 ,
Dec 19, 2021 Dec 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
}
Translate
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
Participant ,
Dec 19, 2021 Dec 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

Translate
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 ,
Dec 19, 2021 Dec 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;
Translate
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
Participant ,
Dec 19, 2021 Dec 19, 2021

The function works. Thank you very much

Translate
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 ,
Dec 19, 2021 Dec 19, 2021

I hope you noticed I changed the pages numbers, too, since page numbers in JS are zero-based.

Translate
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
Participant ,
Dec 19, 2021 Dec 19, 2021

Yes. Thank you

Translate
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 Beginner ,
May 27, 2025 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:

Translate
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 Beginner ,
May 27, 2025 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);

Translate
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 ,
May 27, 2025 May 27, 2025
LATEST

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.

Translate
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 Beginner ,
May 27, 2025 May 27, 2025

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}

Translate
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
Adobe Employee ,
May 27, 2025 May 27, 2025

Hello @qqwe_5278!

 

I hope you are doing well. I am glad to know that the issue was fixed, and thank you for sharing the steps that worked for you.

 

Feel free to reach out if you need any assistance.

Thanks,

Anand Sri.

Translate
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