### PortalTest Class Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/PortalTest.md Demonstrates how to use the PortalTest class to record and replay web server actions. It shows initializing the class, setting recording paths, starting and stopping recording, and replaying recorded actions from XML files. ```ts try { var portalTest = new PortalTest("dbtest", 11000, "peachit"); portalTest.setRecordingPath("c:\\log"); portalTest.startRecording(); PDTools.sleep(60000): // sleeping 60sec and doing something in the web client portalTest.stopRecording(); } catch (exp) util.out(exp); ... try { // Replaying recorded actions from the xml-files of a directory var xmlDir = "c:\\log"; var portalTest = new PortalTest("dbtest", 11000, "peachit"); ... ``` -------------------------------- ### Get File Creation Date Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/DocFile.md An example demonstrating how to retrieve and output the creation date of a file using the context.file object. ```ts var file = context.file; var c_ts = file.getCreationDate(); if (c_ts) util.out(c_ts); ``` -------------------------------- ### File Operations Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/DocFile.md Demonstrates basic file operations including starting an edit session, setting a field value, and committing changes. Includes error handling for failed operations. ```ts var myFile = context.file; if (!myFile) { throw new Error('This file doesn´t exist'); } if (!myFile.startEdit()) { throw new Error(myFile.getLastError()); } myFile.Field = "value"; if (!myFile.commit()) { errorMsg = myFile.getLastError(); if (!myFile.abort()) { errorMsg += '\n' + myFile.getLastError(); } throw new Error(errorMsg); } ``` -------------------------------- ### Get Retention Policies Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/ArchiveServer.md Example demonstrating how to retrieve retention policies from an ArchiveServer using the getRetentionPolicies() method. ```typescript try { var as = context.getArchiveServer("EDA_2022"); var policiesString = as.getRetentionPolicies() util.out(policiesString); } catch (err) { util.out(err) } ``` -------------------------------- ### addFileTypeAgent Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/SystemUser.md Example of how to create file type agents for the current user. ```typescript var currentUser = context.getSystemUser(); if (!currentUser) throw "currentUser is NULL"; var loginNames = new Array(); loginNames.push("user1"); loginNames.push("user2"); if (!currentUser.addFileTypeAgent("testFileType", loginNames)) util.out("Error: " + currentUser.getLastError()); else util.out("OK."); ``` -------------------------------- ### addFileTypeAgentScript Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/SystemUser.md Example of how to create file type agents using a script. ```typescript var currentUser = context.getSystemUser(); if (!currentUser) throw "currentUser is NULL"; if (!currentUser.addFileTypeAgentScript("*", "testScript")) util.out("Error: " + currentUser.getLastError()); else util.out("OK."); ``` -------------------------------- ### Example Usage of context.getFolderPosition Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/Context.md Demonstrates retrieving a folder by name, getting its position using `getFolderPosition`, and handling potential errors. ```ts var folder = context.getFoldersByName("MyPublicFolder").first(); var pos = context.getFolderPosition(folder); if (pos < 0) throw context.getLastError(); ``` -------------------------------- ### Create Subfolder Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/Folder.md Example of creating a subfolder with a specified name and type. ```typescript var parentFolder = context.createFolder("parentFolder", "public"); if (parentFolder) { var subFolder = parentFolder.createSubFolder("subFolder", "dynamicpublic"); if (subFolder) util.out(subFolder.type); else util.out(parentFolder.getLastError()); } ``` -------------------------------- ### Run PDF Tool Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/Util.md Example of how to use the runPDFTool function to overlay text onto a PDF. ```ts const command = "pdfoverlay"; const sourcePdf = "c:\\tmp\\source.pdf"; const targetPdf = "c:\\tmp\\target.pdf"; var data = [{ type: "text", text: "Hello World", size: 16, x: 10, y: 10, invertY: true, page: 0 }]; var res = util.runPDFTool(command, sourcePdf, targetPdf, JSON.stringify(data)); var exitcode = res[0]; if (exitcode !== "0") throw "Executing the otrPdfTool failed: " + exitcode; ``` -------------------------------- ### Add to Outbar Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/Folder.md Example showing how to add a folder to an outbar. ```typescript var folder = context.createFolder("testFolder", "public"); var success = folder.addToOutbar("testOutbar"); if (!success) util.out(folder.getLastError()); ``` -------------------------------- ### Submit Changes Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/ArchiveServer.md Example demonstrating how to set an attribute on an ArchiveServer and submit the changes using setAttribute() and submitChanges(). ```typescript var as = context.getArchiveServer("EDA_2017"); if (as) { as.setAttribute("Host", "127.0.0.1"); as.submitChanges(); } ``` -------------------------------- ### Send Email Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/classes/Email.md Example illustrating how to send an email after setting its subject and body. ```typescript var mail = new Email("receiver@domain.de"); mail.setSubject("Test"); mail.setBody("This is a test mail."); if (!mail.send()) util.out(mail.getLastError()); ``` -------------------------------- ### Set Links Path Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/Util.md Example showing how to set the path for the links browser and then use htmlToText. ```ts util.setLinksPath(util.getServerPath() + "/../addon/links"); context.returnValue = util.htmlToText("
Hello world!
"); ``` -------------------------------- ### Get Absence Start Date Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/SystemUser.md Retrieves the configured start date for user absence. ```ts var absenceStartDate = currentUser.getAbsentFrom(); ``` -------------------------------- ### Dokuments-Mappenbearbeitung mit startEdit/commit Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/Scripting_Programmierhandbuch.md Dieses Codebeispiel demonstriert die Bearbeitung und Speicherung einer Dokuments-Mappe über die Befehle `startEdit()` und `commit()`, analog zur Weboberfläche. ```de startEdit() // Änderungen vornehmen commit() ``` -------------------------------- ### Get Action By Name Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/Folder.md Example of retrieving a user-defined action by its name and modifying its properties. ```typescript var it = context.getFoldersByName("testFolder"); var folder = it.first(); if (folder) { var action = folder.getActionByName("testAction"); if (action) { action.type = "PortalScript"; action.setPortalScript("testScript"); } else util.out(folder.getLastError()); } ``` -------------------------------- ### Safe Usage of startEdit() and commit()/abort() Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/Scripting_Programmierhandbuch.md Provides essential rules for using `startEdit()` in scripts. It stresses verifying the return value of `startEdit()` and ensuring a corresponding `commit()` or `abort()` is always called to prevent locked document copies. It also notes that the Scripting Engine cleans up working copies at script termination, but timely cleanup is not always guaranteed. ```de Stellen Sie sicher, dass `startEdit()` `true` zurückgibt. Stellen Sie sicher, dass zu jedem `startEdit()` ein `commit()` oder `abort()` erfolgt. ``` -------------------------------- ### FolderIterator Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/FolderIterator.md Example demonstrating how to use FolderIterator to get folders by name, copy them, and set their properties. ```ts if (context.getFoldersByName(lstName, "public").size() == 0) { var folderIter = context.getFoldersByName("TemplateFolder", "public"); if (folderIter && folderIter.size() > 0) { var source = folderIter.first(); // fetch list folder var target = source.copyFolder(true, true, true); target.Name = lstName; target.Label = docFile.crmName; target.Type = "public"; } } ``` -------------------------------- ### Key Rules for Scripting Document Modifications Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/Scripting_Programmierhandbuch.md Summarizes the most important rules for scripting document modifications: avoid `startEdit()` and `commit()` if possible, prefer `sync()`, ensure `commit()`/`abort()` pairs for `startEdit()`, and use these operations sparingly due to database load. ```de - Verzichten Sie nach Möglichkeit auf startEdit() und commit(). - Verwenden Sie stattdessen bevorzugt die sync()-Operation. - Sollte startEdit() unverzichtbar sein, stellen Sie sicher, dass immer ein passendes commit() bzw. (im Fehlerfall) ein abort() vorhanden ist. - Gehen Sie sparsam mit diesen Operationen um, da sie Datenbanklast verursachen. ``` -------------------------------- ### Start Workflow Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/classes/DocumentsRemoteJSON.md Example of initiating a workflow for a file with ID 'relations_fi20200000001335' using the workflow pattern ID '352:8172'. ```ts var dr = null; try { dr = new DocumentsRemoteJSON(JSON.stringify(json)); var reqJson = {}; reqJson.file_id = "relations_fi20200000001335"; reqJson.workflow_pattern_id = "352:8172"; dr.StartWorkflow(JSON.stringify(reqJson)); } catch (err) { util.out(err); } finally { if (dr) dr.CloseSession(); } ``` -------------------------------- ### Database Load and Resource Management Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/Scripting_Programmierhandbuch.md Details the database load implications of `startEdit()`, as it requires duplicating the entire document object. This makes `startEdit()` an operation that accesses expensive resources. The document advises using these operations sparingly. ```de Jede Erzeugung einer Arbeitskopie über `startEdit()` verursacht Datenbanklast. Gehen Sie sparsam mit `startEdit()` und `commit()` um. ``` -------------------------------- ### Singleton-Mappen-Skript für LDAP-Konfiguration Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/Scripting_Programmierhandbuch.md Dieses JavaScript-Skript dient zur Verwaltung einer Singleton-Konfigurationsmappe für die LDAP-Kopplung. Es versucht, eine bestehende Konfigurationsmappe zu finden oder eine neue zu erstellen, falls keine vorhanden ist. Das Skript gibt die ID der gefundenen oder erstellten Mappe zurück. Es setzt voraus, dass der Benutzer über entsprechende Berechtigungen verfügt und berücksichtigt nicht den Fall mehrerer sichtbarer Mappen. ```javascript var myFRS = new FileResultset("ldapConfiguration", "", ""); var myMappe = null; if (!myFRS || myFRS.size() <= 0) { myMappe = context.createFile("ldapConfiguration"); } else { myMappe = myFRS.first(); delete myFRS; // free memory! } if (!myMappe) { context.errorMessage = "Could not read file!"; return -1; } return myMappe.getAutoText("id"); ``` -------------------------------- ### Get Server Install Path Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/Context.md Retrieves the installation path of the portal server as a string. This function is available since ELC 3.60a / otrisPORTAL 6.0a. ```ts var installDir = context.getServerInstallPath(); util.out(installDir); ``` -------------------------------- ### EBIS GET Request Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/ArchiveConnection.md Demonstrates how to establish an ArchiveConnection to EBIS and send a GET request to retrieve factory information. It also shows how to handle potential errors by checking the last error message. ```ts var ebisConn = context.getArchiveConnection("ebisStore1"); if (ebisConn) { var factoryInfo = ebisConn.sendEbisRequest("/factory"); var eText = ebisConn.getLastError(); if(eText == "") util.out(factoryInfo); else util.out(eText); } ``` -------------------------------- ### Dokuments-Mappenbearbeitung mit sync Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/Scripting_Programmierhandbuch.md Dieses Codebeispiel zeigt, wie Änderungen an einem DocFile-Objekt direkt vorgenommen und mit dem Befehl `sync()` auf die zugrundeliegende Dokuments-Mappe synchronisiert werden können. ```de // Änderungen am DocFile-Objekt vornehmen sync() ``` -------------------------------- ### Query Files Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/classes/DocumentsRemoteJSON.md Example of how to use the Query function to search for 'crmNote' and 'crmProduct' files, filtering by 'crmSubject' starting with 'Test', sorting by 'crmDescription' in descending order, and requesting specific fields. ```ts var dr = null; try { dr = new DocumentsRemoteJSON(JSON.stringify(json)); var reqJson = {}; reqJson.filetypes = ["crmNote", "crmProduct"]; reqJson.filter = "SETMETHOD(2)crmSubject ~ Test*"; reqJson.sort = "crmDescription-"; reqJson.field_names = ["crmDescription", "crmId", "crmSubject"]; var res = dr.Query(JSON.stringify(reqJson)); util.out("Response: " + res); } catch (err) { util.out(err); } finally { if (dr) dr.CloseSession(); } ``` -------------------------------- ### GetFiles TypeScript Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/classes/DocumentsRemoteJSON.md Provides a TypeScript example for the GetFiles function. It shows how to use DocumentsRemoteJSON to retrieve file information from a folder, including setting the folder name, start index, count, and preview flag. ```ts var dr = null; try { dr = new DocumentsRemoteJSON(JSON.stringify(json)); var reqJson = {}; reqJson.name = "testFolder" reqJson.start_index = 0; reqJson.count = -2; reqJson.preview = true; var res = dr.GetFiles(JSON.stringify(reqJson)); util.out("Response: " + res); } catch (err) { util.out(err); } finally { if (dr) dr.CloseSession(); } ``` -------------------------------- ### Get AutoText Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/Context.md Retrieves the string value of a DOCUMENTS autotext. It supports optional start and end tags for parsing. ```APIDOC getAutoText(`autoText`, `startTag?`, `endTag?`): `string` **Get the String value of a DOCUMENTS autotext.** Parameters: autoText: `string` - the rule to be parsed startTag?: `string` - optional start tag. Default: "%" endTag?: `string` - optional end tag. Default: "%" Returns: `string` - String containing the parsed value of the autotext Example: ```ts util.out(context.getAutoText("currentDate")); ``` ``` -------------------------------- ### ArchivingDescription Configuration Examples Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/DocFile.md Examples demonstrating how to configure and use the ArchivingDescription object for archiving files in different environments (EE.i, EE.x, EAS). It shows setting target archives, servers, status, monitor flags, and registers. ```ts var myFile = context.file; var ad = new ArchivingDescription(); ad.targetArchive = "$(#TOASTUP)\STANDARD"; ad.archiveServer = "myeei"; // since Documents 4.0 using multi archive server ad.archiveStatus = true; ad.archiveMonitor = true; ad.addRegister("all_docs"); // archive all attachments var success = myFile.archive(ad); if (success) { context.returnType = "html"; return ("ArchiveFileID: " + myFile.getAttribute("Key") + "
"); } ``` ```ts var myFile = context.file; var ad = new ArchivingDescription(); ad.targetView = "Unit=Default/Instance=Default/View=DeliveryNotes"; ad.targetSchema = "Unit=Default/Instance=Default/DocumentSchema=LIEFERSCHEINE"; ad.archiveServer = "myeex"; // since Documents 4.0 using multi archive server ad.archiveStatus = true; ad.archiveMonitor = true; ad.addRegister("all_docs"); // archive all attachments var success = myFile.archive(ad); if (success) { context.returnType = "html"; return ("
ArchiveFileID: " + myFile.getArchiveKey() + "
"); } ``` ```ts var myFile = context.file; var ad = new ArchivingDescription(); ad.archiveServer = "myeas"; // using multi archive server ad.archiveStatus = true; ad.archiveMonitor = true; ad.addRegister("all_docs"); // archive all attachments var success = myFile.archive(ad); if (success) { context.returnType = "html"; return ("ArchiveFileID: " + myFile.getArchiveKey() + "
"); } ``` -------------------------------- ### startEdit() - Documents Scripting Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/DocFile.md Switches a DocFile to edit mode, creating a scratch copy for temporary changes. This function mimics the 'Edit' button functionality. Avoid using it in workflow scripts. Returns true on success, false on error. ```APIDOC startEdit(): boolean Returns: true if successful, false otherwise. Since: ELC 3.50 / otrisPORTAL 5.0 See: DocFile.abort Note: Avoid using this function in scripts executed within a workflow (e.g., signal exits, decisions) as it may conflict with existing edit states or automatic edit modes for new files. ``` ```typescript var docFile = context.file; if (!docFile.startEdit()) util.out(docFile.getLastError()); ``` -------------------------------- ### SystemUser Methods Documentation Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/SystemUser.md Provides detailed documentation for SystemUser methods, including their parameters, return values, and usage examples. ```APIDOC getAttribute(attribute: string): string Get the String value of an attribute of the SystemUser. Parameters: attribute (string): String containing the name of the desired attribute Returns: string: String containing the value of the desired attribute Since: ELC 3.50b / otrisPORTAL 5.0b getBackDelegatedFiles(removeFromAgentInbox: boolean): boolean Get back the delegated files. If the user is not present this method returns an error. Parameters: removeFromAgentInbox (boolean): Optional boolean indicating whether the files are removed from agent inbox after getting back by the user. If this parameter is not specified, the value from the user settings in the absent dialog on the web is used. Returns: boolean: true if successful, false in case of any error. Since: DOCUMENTS 4.0d See: setAbsent delegateFilesOfAbsentUser getCustomProperties(nameFilter?: string, typeFilter?: string): CustomPropertyIterator Get a CustomPropertyIterator with all CustomProperty of the user. This method returns a CustomPropertyIterator with the CustomProperty of the user. Parameters: nameFilter? (string): String value defining an optional filter depending on the name typeFilter? (string): String value defining an optional filter depending on the type Returns: CustomPropertyIterator: CustomPropertyIterator Since: DOCUMENTS 4.0a See: context.findCustomProperties SystemUser.setOrAddCustomProperty SystemUser.addCustomProperty getIndividualFolders(): FolderIterator Retrieve a list of individual Folders of the Systemuser. Returns: FolderIterator: FolderIterator containing a list of all individual folders. Since: DOCUMENTS 4.0d See: SystemUser.getPrivateFolder getLastError(shortMessage?: boolean): string Function to get the description of the last error that occurred. Since: DOCUMENTS 5.0g (new parameter shortMessage) Parameters: shortMessage? (boolean): optional Boolean; removes "Error in function: class.method(): " from the message. Default: false Returns: string: Text of the last error as String Since: ELC 3.50b / otrisPORTAL 5.0b See: DocFile.getLastError getOID(oidLow?: boolean): string Returns the object-id. Since: DOCUMENTS 5.0 (new parameter oidLow) Parameters: oidLow? (boolean): Optional flag: If true only the id of the Systemuser object (m_oid) will be returned. If false the id of the Systemuser object will be returned together with the id of the corresponding class in the form "class-id:m_oid". Default: false Returns: string: String with the object-id Since: ELC 3.60c / otrisPORTAL 6.0c getPrivateFolder(folderType): Folder Try to retrieve a particular private Folder of the Systemuser. In addition to the public folders you may define in DOCUMENTS, each DOCUMENTS user has a set of private folders. You might need to access a particular private folder to access its contents, for example. Parameters: folderType: The type of the private folder to retrieve. ``` -------------------------------- ### Getting the Name of an Attachment Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/ArchiveConnectionBlob.md This TypeScript example shows how to retrieve the name of an attachment using the 'name' property of an ArchiveConnectionBlob object. ```typescript var archDoc = xmlserver.downloadBlob(....); util.out(archDoc.name); ``` -------------------------------- ### Get System User Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/SystemUser.md This TypeScript snippet demonstrates how to retrieve the current system user and check if they are a super user. ```ts var currentUser = context.getSystemUser(); if (!currentUser) throw "currentUser is NULL"; util.out(currentUser.isSuperUser()); ``` -------------------------------- ### Comparison of sync() and startEdit() Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/Scripting_Programmierhandbuch.md Compares `sync()` and `startEdit()`, suggesting `sync()` is generally preferred. However, it notes that `sync()` can lead to information loss if a user is editing the same document via the web, as their changes might overwrite script modifications. Exceptions exist for specific scripting events where `sync()` affects the working copy. ```de Bevorzugen Sie `sync()`, um Datenbanklast zu vermeiden. Seien Sie sich des Risikos von Informationsverlusten bei `sync()` bewusst, wenn Benutzer gleichzeitig bearbeiten. ``` -------------------------------- ### Get Subfolder Position Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/Folder.md Demonstrates how to retrieve the position of a subfolder within its parent folder using the getPosition method. ```ts var parentFolder = context.createFolder("parentFolder", "public"); if (parentFolder) { var subFolder1 = parentFolder.createSubFolder("subFolder1", "dynamicpublic"); var subFolder2 = parentFolder.createSubFolder("subFolder2", "onlysubfolder"); if (subFolder1 && subFolder2) { var pos = parentFolder.getPosition(subFolder2); util.out(pos == 1); } } ``` -------------------------------- ### Iterate Through Documents Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/DocumentIterator.md Example of how to iterate through documents in a register using the DocumentIterator. It retrieves the 'Documents' register, gets all documents, and prints their full names. ```ts var docFile = context.file; if (docFile) { var docreg = docFile.getRegisterByName("Documents"); if (docreg) { var docs = docreg.getDocuments(); if (docs && docs.size() > 0) { for (var d = docs.first(); d; d = docs.next()) { util.out(d.fullname); } } } } ``` -------------------------------- ### File Output Examples Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/DocFile.md Demonstrates various ways to output file content as JSON using the `asJSON` method. This includes outputting the entire file, specific fields, and localized or raw data with labels. ```ts var file = context.file; util.out(file.asJSON()); // { // "DlcFile_Title": "Rechnung 17", // "DlcFile_Owner": "Schreiber, Willi", // "DlcFile_Created": "2019-11-08T10:42:42.000Z", // "DlcFile_LastEditor": "Schreiber, Willi", // "DlcFile_LastModified": "2019-11-08T10:45:10.000Z", // "company": "otris software AG", // "invoice_ts": "2019-11-08T10:45:10.000Z", Zulu Time // "invoice_ok": true, // "invoice_no": 17, // "amount": 3.14, // } var file = context.file; var fields = ["DlcFile_Title", "company"]; util.out(file.asJSON(fields)); // { // "DlcFile_Title": "Rechnung 17", // "company":"otris software AG" // } var file = context.file; util.out(file.asJSON([], util.JSON_LOCALE)); // { // "DlcFile_Title": "Rechnung 17", // "DlcFile_Owner": "Schreiber, Willi", // "DlcFile_Created": "08.11.2019 11:42", // "DlcFile_LastEditor": "Schreiber, Willi", // "DlcFile_LastModified": "08.11.2019 11:45", // "company": "otris software AG", // "invoice_date": "08.11.2019 11:45", // "invoice_ok": true, // "invoice_no": 17, // "amount": "3,14", // } // var file = context.file; util.out(file.asJSON([], util.JSON_RAW | util.JSON_LABEL | util.JSON_LOCALE)); // { // "DlcFile_Title": "Rechnung 17", // "DlcFile_Owner": "Schreiber, Willi", // "DlcFile_Created": "08.11.2019 11:42", // .... // "raw": { // "DlcFile_Title": "Rechnung 17", // "DlcFile_Created": "2019-11-08T10:42:42.000Z", // "company": "otris software AG", // ... // }, // "label": { // "DlcFile_Title": "Titel", // "DlcFile_Created": "Erstellt am", // "company": "Kundenname", // ... // } // } ``` -------------------------------- ### Retrieving Attachment Document Key Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/ArchiveConnectionBlob.md This TypeScript example shows how to get the document key of an attachment using the 'docKey' property of an ArchiveConnectionBlob object. ```typescript var archDoc = xmlserver.downloadBlob(....); util.out(archDoc.docKey); ``` -------------------------------- ### Retrieving Attachment MIME Type Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/ArchiveConnectionBlob.md This TypeScript example demonstrates how to get the MIME type of an attachment using the 'mimeType' property of an ArchiveConnectionBlob object. ```typescript var archDoc = xmlserver.downloadBlob(....); util.out(archDoc.mimeType); ``` -------------------------------- ### Download Binärdatei über benutzerdefinierte Aktion Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/Scripting_Programmierhandbuch.md Dieses JavaScript-Snippet zeigt, wie eine benutzerdefinierte Aktion konfiguriert wird, um eine Binärdatei (z.B. PDF) als direkten Download für den Anwender bereitzustellen. Es sucht nach einem bestimmten Dokument in einer Mappe und setzt den `context.returnType` auf 'download:dateiname.ext', bevor es die Datei herunterlädt. ```javascript var myMappe = context.file; if (!myMappe) { context.errorMessage = "Not in a file context!"; return -1; } var reg = myMappe.getRegisterByName("Documents"); if (!reg) { context.errorMessage = "Register not found!"; return -1; } var docIter = reg.getDocuments(); if (docIter && docIter.size() > 0) { for (var doc = docIter.first(); doc; doc = docIter.next()) { if (doc.fullname == pDocument) { context.returnType = "download:" + doc.fullname; return doc.downloadDocument(); } } } ``` -------------------------------- ### XMLHTTPRequest getResponseHeader Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/classes/XMLHTTPRequest.md Demonstrates how to get the value of a specific response header from an XMLHTTPRequest. This allows targeted retrieval of information like 'Content-Type'. ```ts var xmlHttp = new XMLHTTPRequest(); var async = false; var url = "http://localhost:11001/"; xmlHttp.open("POST", url, async); if (xmlHttp.send(content)) util.out(xmlHttp.getResponseHeader("Content-Type")); ``` -------------------------------- ### Add System User Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/Folder.md Example demonstrating how to add a system user to a folder with specific file access rights. ```typescript var folder = context.createFolder("testFolder", "public"); var success = folder.addSystemUser("user1", true, false); if (!success) util.out(folder.getLastError()); ``` -------------------------------- ### Getting the File Key of an Attachment Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/ArchiveConnectionBlob.md This TypeScript example demonstrates how to obtain the file key associated with an attachment using the 'fileKey' property of an ArchiveConnectionBlob object. ```typescript var archDoc = xmlserver.downloadBlob(....); util.out(archDoc.fileKey); ``` -------------------------------- ### ArchiveServer Methods Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/ArchiveServer.md Provides detailed documentation for all methods available on the ArchiveServer interface, including their parameters, return values, and usage. ```APIDOC ArchiveServer: name(): string The technical name of the ArchiveServer. getArchiveConnection(): ArchiveConnection Retrieve the archive connection object for EAS, EBIS or EASY Enterprise XML-Server. The ArchiveConnection object can be used for low level call directly on the archive interface. Returns: ArchiveConnection object if successful, null in case of any error. getAttribute(attribute: string): string Get the String value of an attribute of the ArchiveServer. Note: This function is only for experts. Knowledge about the DOCUMENTS-database schema is necessary! Parameters: attribute: String containing the name of the desired attribute Returns: String containing the value of the desired attribute. getLastError(shortMessage?: boolean): string If you call a method at an ArchiveServer object and an error occurred, you can get the error description with this function. Parameters: shortMessage?: optional Boolean; removes "Error in function: class.method(): " from the message. Default: false Returns: Text of the last error as String. getOID(oidLow?: boolean): string Returns the object-id. Parameters: oidLow?: Optional flag: If true only the id of the ArchiveServer object (m_oid) will be returned. If false the id of the ArchiveServer object will be returned together with the id of the corresponding class in the form class-id:m_oid. Default: false Returns: String with the object-id. getRetentionPolicies(): string Returns a json string with the retention policies of the ArchiveServer. Note: Only available for EAS ArchiveServer Returns: json-String; throws an exception in case of an error. pdo(): PDObject Internal Function returns the PDObject of the ArchiveServer. This function is for internal use only! Returns: PDObject, in case of an error an exception will be thrown. setAttribute(attribute: string, value: string): boolean Set the String value of an attribute of the ArchiveServer to the desired value. Note: This function is only for experts. Knowledge about the DOCUMENTS-database schema is necessary! Parameters: attribute: String containing the name of the desired attribute value: String containing the desired value of the attribute Returns: true if successful, false in case of any error. submitChanges(): void After changes on the ArchiveServer with scripting methods, it is necessary to submit them to make them immediately valid. The settings of the ArchiveServer will be cached in a connection pool to the archive system. The pool does not recognize changes in the ArchiveServer object automatically, therefore it is necessary to call this method after all. Returns: void. ``` -------------------------------- ### Accessing Readable File Size Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/ArchiveConnectionBlob.md This TypeScript example demonstrates how to get the human-readable file size of an attachment using the 'size' property of an ArchiveConnectionBlob object. ```typescript var archDoc = xmlserver.downloadBlob(....); util.out(archDoc.size); ``` -------------------------------- ### XLSXWorksheet Class Overview and Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/XLSXWorksheet.md Provides an overview of the XLSXWorksheet class, explaining its instantiation through XLSXWriter and demonstrating basic usage with cell writing and formatting. ```ts var writer = new XLSXWriter("c:\\tmp\\worksheet.xlsx"); // Add a worksheet with a user defined sheet name. var worksheet1 = writer.addWorksheet("Worksheet1"); // Add a cell format. var format1 = writer.addFormat("format1"); // Set the bold property for the format. format1.setFontStyle("bold"); // Set the alignment for the format format1.setAlign(writer.ALIGN_CENTER); // Write formatted data. worksheet1.writeCell("string", 0, 0, "Hello Excel", format1); // Change the row height worksheet1.setRow(0, 20); // Change the column width worksheet1.setColumn(0, 0, 15); // Save the file. if (!writer.save()) throw writer.getLastError(); ``` -------------------------------- ### Accessing the Local Path of an Attachment Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/ArchiveConnectionBlob.md This TypeScript example shows how to get the local path to an attachment if it's available on the PortalServer, using the 'localPath' property of an ArchiveConnectionBlob object. ```typescript var archDoc = ...; if (archDoc.downloaded) util.out(archDoc.localPath); ``` -------------------------------- ### Skript Logik: Nach dem Speichern Event (Warnung) Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/Scripting_Programmierhandbuch.md Erläutert die Konsequenzen der Ausführung eines Skripts nach dem Speichern einer Mappe. Es wird ausdrücklich davor gewarnt, die Ausführung mit 'return -1;' abzubrechen, da dies zu Problemen mit dem Browser-Refresh führen kann. ```de // Warnung: Bei Ausführung nach dem Speichern (onAfterSave) darf 'return -1;' nicht verwendet werden. // Ein Abbruch würde die Speicherung der Arbeitskopie zwar rückgängig machen, aber den Browser-Refresh verhindern. // Dies führt beim nächsten Speichern zu der Fehlermeldung 'Diese Mappe existiert nicht'. ``` -------------------------------- ### Get User Action Position Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/classes/UserAction.md Illustrates how to retrieve the position of a UserAction within its parent object's action list using the `getPosition` method. ```typescript var it = context.getFoldersByName("testFolder"); var folder = it.first(); if (folder) { var action = folder.getActionByName("testAction"); if (action) util.out(action.getPosition()); } ``` -------------------------------- ### DocFile Export Example Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/DocFile.md Exports a file to an XML format. This example demonstrates how to use the exportXML method with specific parameters for inclusion of documents, status, and monitor information. ```ts var docFile = context.file; docFile.exportXML("c:\\tmp\\myXmlExport.xml", true, false, true); ``` -------------------------------- ### Get All Workflows Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/Context.md Lists all available Workflows and distribution lists. Supports filtering by type using flags, allowing enumeration of simple distribution lists or complete workflows. Examples of flag combinations are provided. ```ts getAllWorkflows(typeFlags?: number): WorkflowIterator.md // Example flag combination: // (1|2|8) evaluates to 11 ``` -------------------------------- ### Example Usage of getBackDelegatedFiles Source: https://github.com/hofi67/documents_scripting_documentation/blob/main/interfaces/SystemUser.md Demonstrates how to use the getBackDelegatedFiles method to retrieve delegated files and handle potential errors. ```ts var currentUser = context.getSystemUser(); if (!currentUser) throw "currentUser is NULL"; if (!currentUser.getBackDelegatedFiles(true)) util.out("Error: " + currentUser.getLastError()); else util.out("OK."); ```