Class: DocumentsContext

documents.sdk DocumentsContext

Constructors

The universal interface for user-exits, gentable and gadgets. It includes opening of dialogs and navigation
to folders, files, the extended search other etc. Additional interfaces are available via the
UserContext,
FileContext,
GadgetContext and the
GentableContext.

  • Since:
    • 5.0a

Methods

closeDialog()

Closes any dialog that is currently displayed.

  • Since:
    • 5.0a
Example
documentsContext.closeDialog();

closeGadget()

Closes a gadget. Currently only useful when the gadget is used in a popup dialog.

  • Since:
    • 5.0

encodeURL(url){String}

Encodes an URL by adding the jsessionid and the cnvid to it. A jsessionid is provided if cookies are disabled only.
URLs must be encoded always if calling custom servlets or jsps and access to the tomcat server session is required.

Name Type Description
url String

the url to be encoded

Returns:
Type Description
String the encoded url
Examples
var encodedUrl = documentsContext.encodeURL("./ext/jsp/invoice/table.jsp");
//  "./ext/jsp/invoice/table.jsp;cnvid=NeRbCno7Vbp5Wj07" (cookies enabled)
//  "./ext/jsp/invoice/table.jsp;jsessionid=686826E7F0B8212A3D97010F3ECB1936;cnvid=NeRbCno7Vbp5Wj07" (cookies disabled)
var encodedUrl = documentsContext.encodeURL("./ext/jsp/invoice/table.jsp" + "?" + documentsContext.getBaseParamsQueryString());
//  "./ext/jsp/invoice/table.jsp;cnvid=NeRbCno7Vbp5Wj07?pri=dopaag&lang=de" (cookies enabled)
//  "./ext/jsp/invoice/table.jsp;jsessionid=686826E7F0B8212A3D97010F3ECB1936;cnvid=NeRbCno7Vbp5Wj07?pri=dopaag&lang=de" (cookies disabled)

executeScript(scriptName, scriptParams, options){Promise|String|undefined}

Executes a server-side global script by its name. Any defined script parameters can be transmitted alike.
The script can either be called synchronous (default) or asynchronous (via options parameter).
If the script result has a defined returnType (defined by context.returnType in the portal script) the
function has no return value and the output depends on the returnType.
With the option dispatch it is possible to always retrieve the script result even if a returnType is defined.
options.dispatch must be set to false (defaults to true) to use the script result as return value.
With option.async = true the function always returns a Promise object. If this option is set it is also
possible to input script parameters defined in the Documents Manager via a dialog. Script parameters added via dialog
will override duplicate scriptParams keys.

Name Type Description
scriptName String

the name of the script

scriptParams Object optional

the input parameters for the script

options Object optional

additional options

Name Type Description
dispatch String optional

default true, if false scriptResult is returned even if the script has a returnType

async String optional

default false, if true the script will be executed asynchronous and will return a promise

useScriptParameterDialog String optional

default false, if true a script parameter dialog will always be displayed if the script has defined parameter, only works if options.async = true

dialogTitle String optional

the title of the script parameter dialog

  • Since:
    • 5.0a
Returns:
Type Description
Promise | String | undefined Promise if options.async === true (see example below), undefined if script result contains returnType, script result String otherwise
Examples
var scriptResult = documentsContext.executeScript("countryScript", { country : "Austria" }, { async : false });
// scriptResult: "Burgenland, Kärnten, Niederösterreich, Oberösterreich, Salzburg, Steiermark, Tirol, Vorarlberg, Wien"
var promise = documentsContext.executeScript("countryScript", { country : "Austria" }, { async : true });
promise.then(function(value) {
	console.log(value); // "Burgenland, Kärnten, Niederösterreich, Oberösterreich, Salzburg, Steiermark, Tirol, Vorarlberg, Wien"
});
var scriptResult = documentsContext.executeScript("aScriptWithReturnType", {param: 'value1'}, { dispatch : false });
// scriptResult is given even if the script has a returnType because dispatch is set to false
---example script---
var capitals = { "Germany" : "Berlin", "Austria" : "Vienna", ... };
return JSON.stringify(capitals);
---example script---

// if options.async === false, the server always returns a string no matter what the original format in the script was. Example to transfer and receive a JSON Object:
var jsonString = documentsContext.executeScript("exampleScript", { }, { async : false });
var capitals = JSON.parse(jsonString);
// capitals: { "Germany" : "Berlin", "Austria" : "Vienna", ... }

getBaseParams(){Object}

Returns all documents application related base parameters as object. It includes both the principal (pri) and the language (lang) parameter.

Returns:
Type Description
Object the base parameters
Example
var urlBaseParams = documentsContext.getBaseParams();  //  -> { "pri" : "dopaag", "lang" : "en" }

getBaseParamsQueryString(){String}

Returns the query string of all documents application related base parameters as query string. It includes both the principal (pri) and the language (lang) parameter.

Returns:
Type Description
String the query string of the base parameters
Example
var urlBaseParams = documentsContext.getBaseParamsQueryString();  //  -> "pri=dopaag&lang=en"

getExtendedSearchContext(){ExtendedSearchContext}

Returns an ExtendedSearchContext.

  • Since:
    • 5.0b
Returns:
Type Description
ExtendedSearchContext The ExtendedSearchContext
Example
var extSearchContext = documentsContext.getExtendedSearchContext();

getFileContext(){FileContext}

Returns a FileContext.

  • Since:
    • 5.0a
Returns:
Type Description
FileContext The FileContext
Example
var fileContext = documentsContext.getFileContext();

getGadgetContext(){GadgetContext}

Returns a GadgetContext.

  • Since:
    • 5.0c
Returns:
Type Description
GadgetContext The GadgetContext
Example
var gadgetContext = documentsContext.getGadgetContext();

getGentableContext(){GentableContext}

Returns a GentableContext.

  • Since:
    • 5.0a
Returns:
Type Description
GentableContext The GentableContext
Example
var gentableContext = documentsContext.getGentableContext();

getI18nContext(){I18nContext}

Returns an I18nContext.

  • Since:
    • 5.0b
Returns:
Type Description
I18nContext The I18nContext

getLocalStorage(key){LocalStorage}

Returns a persistent local web storage by its key. If the key is omitted, a "custom" local storage is returned by default.

Name Type Description
key String

the key of the storage

  • Since:
    • 5.0c
Returns:
Type Description
LocalStorage The LocalStorage
Examples
var localStorage1 = documentsContext.getLocalStorage("oceanic");
var localStorage2 = documentsContext.getLocalStorage();  //  "custom"

getSessionStorage(key){SessionStorage}

Returns a transient session web storage by its key. If the key is omitted, a "custom" session storage is returned by default.

Name Type Description
key String

the key of the storage

  • Since:
    • 5.0c
Returns:
Type Description
SessionStorage The SessionStorage
Examples
var sessionStorage1 = documentsContext.getSessionStorage("oceanic");
var sessionStorage2 = documentsContext.getSessionStorage();  //  "custom"

getURL(type, options){String}

Creates and returns a documents application servlet url by a defined type. Optional parameters must be provided in some cases.

Name Type Description
type String

the type of the servlet url that should be returned

annotation (options: fileId, documentId) URL to access the annotations of a pdf/tif file
controlSheet (options: fileId, registerId) URL for a control sheet
gadget URL for a gadget
docDownload URL to download a file (options: fileId, documentId, attachmentType, versionId, attachmentMode)
pdfjsViewer URL to access the pdfjs viewer
otrisViewer URL to access the otris viewer
report URL for a report
docUpload URL to access the upload servlet
userLogin URL to login the current user
userLogout URL to logout the current user

options Object optional

additional options needed for some types

Name Type Description
absolute String optional

default false, if true the function will return an absolute url, otherwise a relative url

fileId String optional

the id of the file

documentId String optional

the id of the file document

registerId String optional

the id of the file register

filename String optional

the file name of a file document

attachmentMode Boolean optional
attachmentType String optional
versionId String optional

the id of a file document version

  • Since:
    • 5.0c
Returns:
Type Description
String the created url
Example
var fileContext = documentsContext.getFileContext();
var urlParams = {
  fileId : fileContext.getFileId(),
  documentId : fileContext.getDocumentId()
};

documentsContext.getURL("annotation", urlParams);
//  -> "http://localhost:8081/srv/annotation;cnvid=[...];jsessionid=[...]?fileId=dopaag_fi201600000386&documentId=dopaagdc00000000000289"

getUserContext(){UserContext}

Returns the UserContext of the current system user.

  • Since:
    • 5.0a
Returns:
Type Description
UserContext The UserContext
Example
var userContext = documentsContext.getUserContext();

openConfirmationDialog(title, message, onOk, onCancel, onClose)

Displays a dialog window that requests the current system user for confirmation.
The dialog window is displayed in front of the main window and system users always have to interact with it before they can return to the main window.
Note that unlike a window.prompt() dialog, the execution of the current program flow is not paused until the user cancels or confirms the dialog.

Name Type Description
title String

the title of the dialog window

message String

the confirmation message text

onOk function

a function that is executed if the user clicks "OK"

onCancel function

a function that is executed if the user clicks "Cancel"

onClose function

a function that is executed if the user clicks "OK", "Cancel" or "X". The function is executed after the onOk or onCancel function.

Example
var title = "Confirmation Dialog";
var message = "Confirmation message text inside the dialog.";
var onOk = function() { console.log("onOk"); }
var onCancel = function() { console.log("onCancel"); }
var onClose = function() { console.log("onClose"); }

documentsContext.openConfirmationDialog(title, message, onOk, onCancel, onClose);

openExtendedSearchView()

Changes the current view to the extended search view.
Caution: This function will not process any actions if the user is currently in edit mode.

  • Since:
    • 5.0a

openFileView(fileId, registerId, documentId, options)

Changes the current view to a file view. It is allowed to navigate to a file (cover), to a register or to a document.
Caution: This function will not process any actions if the user is currently in edit mode.

Name Type Description
fileId String

the id of the file

registerId String optional

the id of the file register

documentId String optional

the id of the file document

options Object optional
Name Type Description
autoOpenDocumentMode Boolean optional

, default: true

checkConstraints Boolean optional

if constraints should be checked or not, default: true

startFileEditMode Boolean optional

if file edit mode should be started or not, default: false

registerBarState String optional

"open", "min", "closed", default :

  • Since:
    • 5.0a
Examples
documentsContext.openFileView(fileId);
documentsContext.openFileView(fileId, registerId);
documentsContext.openFileView(fileId, registerId, documentId);
documentsContext.openFileView(fileId, null, null, { startFileEditMode : true, registerBarState : "closed" });

openFolderView(folderId)

Changes the current view to a folder view. It is allowed to navigate to any private or public folder.
Caution: This function will not process any actions if the user is currently in edit mode.

Name Type Description
folderId String

the id of the folder

  • Since:
    • 5.0a

openFrameDialog(title, frameSrc, options)

Displays a dialog with an embedded iframe.

Name Type Description
title String

the title of the dialog window

frameSrc String

the url of the embedded iframe

options Object
Name Type Description
width Number optional

the width of the dialog, default: 400

height Number optional

the height of the dialog, default: 300

top Number optional

the distance from the top of the window

left Number optional

the distance from the left of the window

frameStyles Object optional

the styles of the dialog

frameStyleClasses Object optional

the classes of the dialog

onClose function optional

function to execute when close is clicked

onOk function optional

function to execute when ok is clicked

onCancel function optional

function to execute when cancel is clicked

  • Since:
    • 5.0c
Example
var title = "Product";
var url = documentsContext.encodeURL("./ext/jsp/invoice/table.jsp" + "?" + documentsContext.getBaseParamsQueryString());

documentsContext.openFrameDialog(title, url, {
	width : 800,
	height : 400,
	frameStyles : { background-color : "darkgrey" },
	frameStyleClasses : [ "dialogFrame" ],
	onClose : function() { console.log("onClose"); },
	onOk : function() { console.log("onOk"); },
	onCancel : function() { console.log("onCancel"); }
});

openHomeView()

Changes the current view to the start screen view.
Caution: This function will not process any actions if the user is currently in edit mode.

  • Since:
    • 5.0d
Example
documents.sdk.exitRegistry.registerFileFieldExitCallback("erpInvoice", "erpInvoiceNumber", function(documentsContext, options) {
	documentsContext.openHomeView();
}

openHtmlDialog(title, html, onOk, onClose)

Displays a html dialog window.
The dialog window is displayed in front of the main window and system users always have to interact with it before they can return to the main window.
Note that unlike a window.alert() dialog, the execution of the current program flow is not paused until the user cancels or confirms the dialog.

Name Type Description
title String

the title of the dialog window

html String

the inner html content source

onOk function

a function that is executed if the user clicks "OK"

onClose function

a function that is executed if the user clicks "OK" or "X". The function is executed after the onOk function.

Example
var title = "HTML Dialog";
var html = "<div style=\"background-color: darkgrey; color: darkred;\">TestDiv</div>";
var onOk = function() { console.log("onOk"); }
var onClose = function() { console.log("onClose"); }

documentsContext.openHtmlDialog(title, html, onOk, onClose);

openMessageDialog(title, message, onOk, onClose)

Displays a message dialog window.
The dialog window is displayed in front of the main window and system users always have to interact with it before they can return to the main window.
Note that unlike a window.alert() dialog, the execution of the current program flow is not paused until the user cancels or confirms the dialog.

Name Type Description
title String

the title of the dialog window

message String

the message text

onOk function

a function that is executed if the user clicks "OK"

onClose function

a function that is executed if the user clicks "OK" or "X". The function is executed after the onOk function.

Example
var title = "Message Dialog";
var message = "Message text inside the dialog.";
var onOk = function() { console.log("onOk"); }
var onClose = function() { console.log("onClose"); }

documentsContext.openMessageDialog(title, message, onOk, onClose);

openOutbar(options)

Opens the outbar with the given name.

Name Type Description
options Object
Name Type Description
name String

Possible values:
OutbarPublicFolder //The outbar for public folders (Documents Manager - Settings - Documents (display) - Combined folder tree not checked)
OutbarPrivateFolder //The outbar for private folders (Documents Manager - Settings - Documents (display) - Combined folder tree not checked)
OutbarCombinedFolder //The outbar for a combination of public and private folders (Documents Manager - Settings - Documents (display) - Combined folder tree checked)
OutbarHitTree //The outbar for a hit tree (Documents Manager - Settings - Global Settings - Hit tree checked)
User defined outbars can be accessed by their name (Documents Manager - settings - Outbars).

  • Since:
    • 5.0d
Example
documents.sdk.exitRegistry.registerFileFieldExitCallback("erpInvoice", "erpInvoiceNumber", function(documentsContext, options) {
	documentsContext.openOutbar({
		name: "OutbarPublicFolder"
	});
}

openTableDataDialog(title, url, options)

Opens a dedicated dialog for the tabledata plugin.
Basically, there are two different dialog types available, one (internal) iframe dialog (default) and another (external) popup window dialog.
The internal iframe dialog appears like an ordinary DOCUMENTS 5 dialog, the external popup window dialog is the more traditional way.
This function supports fully automatic setting of file field data, gentable row data or email dialog recipient data on a tabledata row selection.
Alternatively, a custom handler function can be implemented which will be executed on tabledata row selection.
If the automatic field setting should be used, the exitOptions option must be specified. Otherwise, if a custom row selection handler should be used, the the onSelect option must be specified.
If both options are set by accident, onSelect option overrides the exitOptions option and also any automatic data setting.
See the examples below for recommended implementations of detail.jsp. Legacy D5 implementations of detail.jsp are fully supported so updating the code is not mandatory in most cases.

Name Type Description
title String

the title of the dialog window

url String

the url of the table.jsp

options Object
Name Type Description
onSelect function optional

custom handler function that is executed after the selection of a tabledata row entry, the selected data is available as a function parameter.
Notice: If this option is set, none of the fields will be set automatically.

exitOptions Object optional

the options object of the registered exit callback function, see examples below for details.
Should be provided if options.onSelect option is not set.

popupWin Boolean optional

true, if an (external) popup window should be used to display the tabledata, otherwise an (internal) iframe dialog is used (default)

width Number optional

the width of the dialog, default: 400

height Number optional

the height of the dialog, default: 300

top Number optional

the top position of the dialog

left Number optional

the left position of the dialog

onClose function optional

custom handler function that is executed when the dialog is closed, not available if popupWin: true is set

sortColumn String optional

the column that sorts the tabledata, add '+' or '-' at the end of the column name to set the sort order. Default: '+'

searchText String optional

the default search text, tabledata is searched on opening

searchColumn String optional

the column to search the searchText in

params Object optional

additional parameter that will be added to the url

  • Since:
    • 5.0c
Examples
**custom tabledata row selection handler**

documents.sdk.exitRegistry.registerFileFieldExitCallback("crmContact", "crmName", function(documentsContext, options) {
	var title = "Ansprechpartner";
	var url = documentsContext.encodeURL("./ext/jsp/tabledata/table.jsp" + "?" + documentsContext.getBaseParamsQueryString());
 
 documentsContext.openTableDataDialog(title, url, {
 	width: 1000,
 	height: 400,
 	popupWin: false,  //  optional
 	onSelect: function(data) {
 		documentsContext.openMessageDialog("", JSON.stringify(data));
 		console.log(data);
 	},
 	sortColumn: "PLZ-", //sort with column PLZ in descending order
 	searchColumn: "PLZ", //search in column PLZ	
 	searchText: "531" //search for values that contain 531
 });
});
**automatic field data setting**

documents.sdk.exitRegistry.registerFileExitCallback("crmContact", "FileEmail.recipients", function(documentsContext, options) {
 var title = "Ansprechpartner";
 var url = documentsContext.encodeURL("./ext/jsp/email/table.jsp" + "?" + documentsContext.getBaseParamsQueryString());
 
 documentsContext.openTableDataDialog(title, url, {
 	width: 1000,
 	height: 400,
 	popupWin: false,  //  optional
 	exitOptions: options  //  mandatory for automatic field setting
 });
});
**detail.jsp, file field data**

var fieldData = {
	crmName: '<tab:detail id="Firmentabelle" name="Kontaktperson" escapeMode="script" removeCRLF="true" />'.split(/\s+/)[1],  //  split "firstName lastName"
	crmFirstName: '<tab:detail id="Firmentabelle" name="Kontaktperson" escapeMode="script" removeCRLF="true" />'.split(/\s+/)[0],  //  split "firstName lastName"
	crmAccountnumber: '<tab:detail id="Firmentabelle" name="Kunden-Code" escapeMode="script" removeCRLF="true" />',
	[...]
};

(window.opener || parent).postMessage({
	action: "<%= request.getParameter("actionId") %>",
	data: fieldData
}, "*");
**detail.jsp, gentable row data**

var rowData = {
	amount: '<tab:detail id="Firmentabelle" name="Lagerbestand" escapeMode="script" removeCRLF="true" />',
	itemno: '<tab:detail id="Firmentabelle" name="Artikel-Nr" escapeMode="script" removeCRLF="true" />',
	[...]
};

(window.opener || parent).postMessage({
	action: "<%= request.getParameter("actionId") %>",
	data: rowData
}, "*");
**detail.jsp, email dialog recipient data**

var emailData = {
	lastName: '<tab:detail id="Personaltabelle" name="Nachname" escapeMode="script" removeCRLF="true" />',
	firstName: '<tab:detail id="Personaltabelle" name="Vorname" escapeMode="script" removeCRLF="true" />'
};

(window.opener || parent).postMessage({
	action: "<%= request.getParameter("actionId") %>",
	data: emailData.firstName + "." + emailData.lastName + "@dopa.ag"
}, "*");

startBusyPanel(view)

This function locks a defined view for the current user by a view identifier.
Valid view identifiers are Workspace, MainTree, MainList, MainFile, MainFileGentable.

Name Type Description
view String

the identifier of the view that is to be locked

Example
//  notice: example uses an asynchronous script action call (with promise)
var fileContext = documentsContext.getFileContext();

documentsContext.startBusyPanel("MainFile");

fileContext.executeScript("countryScript", { country : "Austria" }, { "async" : true }).then( function(result) {
	//  process the file script action result
	documentsContext.stopBusyPanel("MainFile");
});

stopBusyPanel(view)

This function unlocks a defined view for the current user by a view identifier.
Valid view identifiers are Workspace, MainTree, MainList, MainFile, MainFileGentable.

Name Type Description
view String

the identifier of the view that is to be unlocked

updateFileView()

Updates the current file view.
In file edit mode, this operation automatically stores the values of all visible file fields while ignoring any constraints.

  • Since:
    • 4.0