Copy link to clipboard
Copied
Hello,
I currently have a title page with form fields that I would like to automate the filling of via javascript. I have set this process up using a tab dlm file (txtfileloc) with the columns titled the same as my form fields and the rows in the same order as the names array. Additionally, I want to insert pages into the document based off of the array using the insert pages function. Both of these functions appear to be working fine with one exception. The problem is that for each iteration of the loop, instead of starting fresh with my title page again, the loop is just updating the previous file with the new results (so file "b_final.pdf" has the form fields from b, but includes the insert pages results pages from both a and b. C includes the results from a,b and c etc.). I have tried using the closeDoc function at the end of the loop to fix this, but this causes an error and after research I found this is because code is not processed after closeDoc . Does anyone have any advice on how to get the loop to start fresh with the title page each time?
For reference, I have included my current code below:
var txtfileloc = "/C/Users/Desktop/Test Files/input.txt";
var infileloc = "/C/Users/Desktop/Test Files/import/";
var outfileloc = "/C/Users/Desktop/Test Files/output/";
var title = "/C/Users/Desktop/Test Files/Title Page Draft.pdf";
var count=0;
names = ['a','b', 'c', 'd', 'e'];
for (i = 0; i < names.length; i++) {
this.importTextData(txtfileloc,count)
this.insertPages({cPath:infileloc+names+".pdf"});
this.saveAs(outfileloc+names+"_final.pdf");
var count=count+1;
app.openDoc(title);
};
Many thanks in advance, I have spent several days trying to resolve this with no luck.
- Kayla
Change the name of the "title" variable to something else. There's a built-in property with that name and it's conflicting with your variable.
Copy link to clipboard
Copied
Hello,
I currently have a title page with form fields that I would like to automate the filling of via javascript. I have set this process up using a tab dlm file (txtfileloc) with the columns titled the same as my form fields and the rows in the same order as the names array. Additionally, I want to insert pages into the document based off of the array using the insert pages function. Both of these functions appear to be working fine with one exception. The problem is that for each iteration of the loop, instead of starting fresh with my title page again, the loop is just updating the previous file with the new results (so file "b_final.pdf" has the form fields from b, but includes the insert pages results pages from both a and b. C includes the results from a,b and c etc.). I have tried using the closeDoc function at the end of the loop to fix this, but this causes an error and after research I found this is because code is not processed after closeDoc . Does anyone have any advice on how to get the loop to start fresh with the title page each time?
For reference, I have included my current code below:
var txtfileloc = "/C/Users/Desktop/Test Files/input.txt";
var infileloc = "/C/Users/Desktop/Test Files/import/";
var outfileloc = "/C/Users/Desktop/Test Files/output/";
var title = "/C/Users/Desktop/Test Files/Title Page Draft.pdf";
var count=0;
names = ['a','b', 'c', 'd', 'e'];
for (i = 0; i < names.length; i++) {
this.importTextData(txtfileloc,count)
this.insertPages({cPath:infileloc+names+".pdf"});
this.saveAs(outfileloc+names+"_final.pdf");
var count=count+1;
app.openDoc(title);
};
Many thanks in advance, I have spent several days trying to resolve this with no luck.
- Kayla
Change the name of the "title" variable to something else. There's a built-in property with that name and it's conflicting with your variable.
Copy link to clipboard
Copied
Are you running this code from the JS Console? If so, you should use a variable to reference the document (instead of the "this" variable), and then close the document at the end of each iteration, and re-open it, assigning the return value of openDoc to that variable.
Also, change this line:
var count=count+1;
To just:
count=count+1;
Actually, you don't need the count variable at all. You can simply use the i variable.
Copy link to clipboard
Copied
Thank you for your quick reply! I am running this code from a stored action wizard item, that executes JS. I tried to follow your advice and updated my code to the following:
/* Javascript code for automation of file merge */
var txtfileloc = "/C/Users/Desktop/Test Files/input.txt";
var sasfileloc = "/C/Users/Desktop/Test Files/SAS/";
var outfileloc = "/C/Users/Desktop/Test Files/output/";
var title = "/C/Users/Desktop/Test Files/Title Page Draft.pdf";
var count=0;
names = ['a', 'b', 'c', 'd','e'];
for (i = 0; i < names.length; i++) {
openDoc = app.openDoc(title);
openDoc.importTextData(textfileloc,count)
openDoc.insertPages({cPath:sasfileloc+names+".pdf"});
openDoc.saveAs(outfileloc+names+"_final.pdf");
openDoc.closeDoc();
count=count+1;
};
~~~~~~~ End code.
I get this error though, which is what I received before when trying to use the closeDoc command.
DeadObjectError: Object is dead.
Doc.title:11:Batch undefined:Exec
Copy link to clipboard
Copied
Change the name of the "title" variable to something else. There's a built-in property with that name and it's conflicting with your variable.
Copy link to clipboard
Copied
Thank you! This resolved my problem and I was able to get the loop running correctly.