Copy link to clipboard
Copied
Hi
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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}
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
The function works. Thank you very much
Copy link to clipboard
Copied
I hope you noticed I changed the pages numbers, too, since page numbers in JS are zero-based.
Copy link to clipboard
Copied
Yes. Thank you
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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}
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now