Copy link to clipboard
Copied
I have a 4 page assessment - when completed it has a button to generate a 2 page report. One of the report's pages is called 'report 1', the other is called 'spasticity'. If a checkbox on the final page of the assessment is checked, 'spasticity' should be spawned, if not checked, 'report1' should be spawned. The other page in the report should be spawed either way. The following step is to print these 2 pages as a separate PDF, then delete both pages, leaving the 4 page assessment. I've tried an if/else I thought would be simple but cannot get it to work. Any advice would be great, thanks!!
Copy link to clipboard
Copied
Thanks for all your help Thom - finally sorted it (wouldn't have got there without your advice). I was using the checkbox value "Yes" to spawn and the Export Value for the checkbox was always "Yes" so exported the same templates regardless. In the end, updated the script to the below and now working OK.
var checkbox = this.getField("spasrep");
var templateChecked = this.getTemplate("spasticity");
var templateUnchecked = this.getTemplate("report1");
var templatemeasure = this.getTemplate("report2");
if (checkbox.isBoxChecked(0)) {
templateChecked.spawn();
templatemeasure.spawn();
templateUnchecked.remove();
} else {
templateUnchecked.spawn();
templatemeasure.spawn();
templateChecked.remove();
}
Copy link to clipboard
Copied
So are the 'report 1' and 'spasticity' pages already setup as page templates and hidden? If so, are those the "template" names? Why are they being spawned and then deleted? Maybe there is a better way to accomplish your goal?
Copy link to clipboard
Copied
Yes, there are three report pages set up as templates and hidden: 'report1', 'report2', 'spasticity' (they are the template names). The idea is once the first 4 pages are completed (this is the assessment), the user should click a button to generate a report (includes 2 template pages), and the next step is that the print panel opens and is set to print just the 2 report pages and then delete these pages from the file. So the assessment ends up being 1 file and the report a separate file. I did have the print/delete javascript working correctly when the report didn't require a separate page based on the checkbox. Hope that makes some sense. Thanks
Copy link to clipboard
Copied
Sounds like you are close. Could be a simple error with the "if". So two more questions.
Are any errors reported in the Console Window (Ctrl-J), and can you post the (non-working) code you are using?
Copy link to clipboard
Copied
Thanks Thom -
The below code works when I just had to generate the same 2-page report regardless of checked boxes:
Spawn report
this.spawnPageFromTemplate("report1",this.numPages, false, false);
this.spawnPageFromTemplate("report2",this.numPages, false, false);
Print just report
var firstPage = 5;
var lastPage = 6;
this.print({nStart: firstPage-1, nEnd: lastPage-1});
Delete report pages
this.deletePages({nStart: this.numPages-2, nEnd: this.numPages-1});
Below is the code that's not working when trying to spawn based off checkboxes:
if (this.getField("spasrep").value != "Off") {
this.getTemplate("report1").spawn();
this.getTemplate("report2").spawn();
}
else {
this.getTemplate("spasticity").spawn();
this.getTemplate("report2").spawn();
}
This is the error reported
InvalidArgsError: Invalid arguments.
printParams.print:5:Field reportword:Mouse Up
Copy link to clipboard
Copied
The error code makes no sense. It's saying the print parameters are invalid, probably the page range. But your new code does not inlcude the print. It's acting as if it is still running the old code, where the print is on line 5.
Seems like there is some old code hanging about somewhere.
Copy link to clipboard
Copied
Still bothering you - you were right, there was some old code after checking the Javascripts so removed that and not getting an error any longer. Issue is still when using the 'spawn' code, regardless of checking the 'spasticity' checkbox, it still spawns and prints the 'spasticity' template. Would it be something to do with the ordering of the templates (e.g. would it just print the last 2 pages of the document anyway)?
Copy link to clipboard
Copied
That behavior would indicate that the "if" statement is always returning "false". Or that there is some other issue, such as the templates are named incorrectly. So, some debug is needed.
The first thing I'd do is run each line of the spawn code individually in the console window to ensure the templates are what you think they are.
Then I'd run the condition code in the "if" statement to see what it returns when the checkbox is checked and not checked.
Copy link to clipboard
Copied
Thanks for all your help Thom - finally sorted it (wouldn't have got there without your advice). I was using the checkbox value "Yes" to spawn and the Export Value for the checkbox was always "Yes" so exported the same templates regardless. In the end, updated the script to the below and now working OK.
var checkbox = this.getField("spasrep");
var templateChecked = this.getTemplate("spasticity");
var templateUnchecked = this.getTemplate("report1");
var templatemeasure = this.getTemplate("report2");
if (checkbox.isBoxChecked(0)) {
templateChecked.spawn();
templatemeasure.spawn();
templateUnchecked.remove();
} else {
templateUnchecked.spawn();
templatemeasure.spawn();
templateChecked.remove();
}
Copy link to clipboard
Copied
I'm sure this code is also reporting errors in the Console window.
There is no "template.remove()" function.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now