A HostDocument object represents an application document object inside the host application. Information such as the document's caption or document location can be retrieved.
// A HostDocument is one open document window in the host application.
// Scripts do not construct them; they come from HostApp:
//
// HostApp.getDocuments() every open document, as an array
// HostApp.getActiveDocument() the one in front, or null
// HostApp.getDocumentById(id)
// HostApp.newDocument(), HostApp.open()
const documents = HostApp.getDocuments();
let output = `${documents.length} open document(s)\n\n`;
for (const doc of documents) {
// getType() gives "table", "query", "report", "editor" or "web", and
// null for a kind it does not recognise. getLocation() is null for
// a document that was never saved -- a new, untitled query, say.
const type = doc.getType();
const location = doc.getLocation();
output += `${doc.getCaption()}\n`;
output += ` type: ${type === null ? "unknown" : type}\n`;
output += ` location: ${location === null ? "(none)" : location}\n`;
}
const active = HostApp.getActiveDocument();
if (active !== null) {
// setCaption() changes the tab text only; it does not rename or move
// whatever the document was loaded from
active.setCaption(`* ${active.getCaption()}`);
output += `\nmarked the active document: ${active.getCaption()}`;
}
alert(output); A string containing the caption, or null upon error
Returns the document's current caption. If the document is no longer open, null is returned
A string containing the document location, or null upon error
Returns the document's location. This can be a internal table name, a filename, or a url.
A string containing the document type, or null upon error
Returns the document's type as a string This value may be "table", "editor", "query", "report", or "web". If the document fails (perhaps because the document no longer exists), null is returned
True upon success, false otherwise
Calling setCaption will update the caption that is displayed for the document.