REPORT TEMPLATE - Spawn, Extract, Rename, & Delete
- September 28, 2023
- 1 reply
- 1641 views
So, I have stumbled upon a trifecta by managing to get a script working that spawns, extracts, and deletes the spawned page from the original document -- effectively creating a separate uneditable report document using my read-only "DISPLAY..." fieldnames method in a template contained within the parent document. As the report document is always spawned to the last page, I have set the extract & delete to the last page as well.
//Working Script
this.getTemplate("TRANSCOM").spawn();
var sourceDocument = this;
var totalPageCount = this.numPages;
this.pageNum = totalPageCount - 1;
this.extractPages({nStart: this.pageNum =
totalPageCount - 1})
sourceDocument.deletePages(totalPageCount - 1);
//END
Unfortunately, I require a superfecta and have failed miserably in accomplishing a "save as" or script prompted "rename" of the extracted page in addition to the previously successful spawn/extract/delete. I have attempted numerous methods with zero success to include attempts of scripting a predetermined filename -- all to no avail.
//Nonworking Script
this.getTemplate("TRANSCOM").spawn();
var sourceDocument = this;
var totalPageCount = this.numPages;
this.pageNum = totalPageCount -1;
this.extractPages({nStart: this.pageNum = totalPageCount - 1});
extractedPageFile.rename(newFilePath);
var newFilename = app.response("TRANSCOM");
if (newFilename) {
var currentPath = this.path;
var fileExtension = currentPath.substring(currentPath.lastIndexOf("."));
var newPath = currentPath.substring(0, currentPath.lastIndexOf("/") + 1) + newFilename + fileExtension;
this.saveAs(newPath);
this.closeDoc(true);
app.openDoc(newPath);
} else {
app.alert("Please rename file using the following format 'TRANSCOM-ddMMMyyyy'.");
}
sourceDocument.deletePages(totalPageCount - 1);
//END
I've managed to get the "newFilename & app.response" working independently as a scripted button but once combined with the template spawn and extraction, there is an all stop. Does anybody have any ideas? Any and all assistance is greatly appreciated. 🙂
