JavaScript-API

DeskClient JavaScript API

This section explains how external web applications can trigger document actions within the DeskClient.

If an external web application is integrated in the DeskClient via 'Tools' or browser tab, it can trigger (document) actions via JavaScript functions. The following actions also work within the preview view of a document inside the DeskClient.

API Documentation

openDocumentInEditor

Opens and/or focuses the document with the given UUID in an editor.

Parameters

uuid: The UUID of the document to open as string

Example

openDocumentInEditor('d70df790-17f1-44e2-b052-997235f6f7a5')

getDocument

Returns the document of the current editor as JSON string or null if the browser is not associated with any document editor.

Parameters

No parameters.

Example

getDocument()

Note that the methode provides a JSON string. To use it as a JavaScript object you need to parse it. For simple usage you can create a function in your application.

function getSophoraDocument() {
 return getSophoraDocumentOfJson(getDocument());
}

function getSophoraDocumentOfJson(documentJson) {
 return JSON.parse(documentJson);
}

getDocumentByUuid

Returns the document with the given UUID as JSON string.

Parameters

uuid: The UUID of the document as string

Example

getDocumentByUuid('d70df790-17f1-44e2-b052-997235f6f7a5')

Note that the method provides a JSON string. To use it as a JavaScript object you need to parse it. For simple usage you can create a function in your application.

function getSophoraDocumentByUuid(uuid) {
 return getSophoraDocumentOfJson(getDocumentByUuid(uuid));
}

function getSophoraDocumentOfJson(documentJson) {
 return JSON.parse(documentJson);
}

getDocumentByExternalId

Returns the document with the given external ID as JSON string.

Parameters

externalId: The external ID of the document as string

Example

getDocumentByExternalId('Fashion-Report-2020')

getDocumentBySophoraId

Returns the document with the given Sophora ID as JSON string.

Parameters

sophoraId: The Sophora ID of the document as string

Example

getDocumentBySophoraId('Fashion-Reports100')

getDocumentStateImageIdentifierByUuid

Returns the identifier for the state image of the document with the given UUID.

Parameters

uuid: The UUID of the document as string (may be null for new documents)

Example

getDocumentStateImageIdentifierByUuid('d70df790-17f1-44e2-b052-997235f6f7a5')

getLockOwnerByUuid

Returns the user who has the lock of the document with the given UUID. Returns null if the document is not locked or the current user has the lock.

Parameters

uuid: The UUID of the document as string (may be null for new documents)

Example

getLockOwnerByUuid('d70df790-17f1-44e2-b052-997235f6f7a5')

getSelectValuesByExternalId

Returns the select values document as JSON string.

Parameters

externalId: The ExternalID of the select values document to convert to JSON string

Example

getSelectValuesByExternalId('751c382b-bed1-475e-8ec8-29e70d4c77f7')

getSelectValueListByExternalIdForStructurePath

Returns a list of select values documents as JSON string.

Parameters

  • externalId: The ExternalID of the select values document to convert to JSON string
  • structure path: The path of the structure node to search for select values in

Example

getSelectValueListByExternalIdForStructurePath('751c382b-bed1-475e-8ec8-29e70d4c77f7', '/system')

getUserDisplayName

Returns the display name of the given user.

Parameters

username: The user name of the user as string (may be null)

Example

getUserDisplayName('guest')

setBoolean, setDouble, setLong, setDate, setString, setUuidReference, setExternalIdReference

Sets a property of the current document and makes the editor dirty if anything changes. If the editor is opened read-only, no values will be updated.

Returns true if setDirty() was called on the editor or false if nothing changed (for example because the editor is read-only).

Parameters

  • propertyName: The name of the property that is to be set.
  • value: The value to be set in the document of the editor

Example

  • setString('sophora-content:title', 'New title value')
  • setDate('sophora-content:date', Date.now())

setBooleans, setDoubles, setLongs, setDates, setStrings, setUuidReferences, setExternalIdReferences

Sets a property of the current document and makes the editor dirty if anything changes. If the editor is opened read-only, no values will be updated.

Returns true if setDirty() was called on the editor or false if nothing changed (for example because the editor is read-only).

Parameters

  • propertyName: The name of the property that is to be set.
  • values: An array of values to be set in the document of the editor

Example

setStrings('sophora-content:titles', ["title1", "title2", "title3"])

removeProperty

Removes a property of the current document and makes the editor dirty if anything changes. If the editor is opened read-only, no values will be updated.

Returns true if setDirty() was called on the editor or false if nothing changed (for example because the editor is read-only).

Parameters

propertyName: The name of the property that is to be removed.

Example

removeProperty('sophora-content:title')

registerDocumentChangeListenerFunction

Registers a JavaScript function that is called when a document is changed. The function will receive the event object as parameter.

Example of a parameter object:

{
 "uuid":"78390270-cd40-430b-8f14-e17f5966f5ee",
 "sophoraId":"test100",
 "externalId":"test-external-ID",
 "primaryType":"test-nt:document",
 "oldState":{
 "state":"IN_PROCESS",
 "deleted":false,
 "enabled":true,
 "liveVersionAvailable":false,
 "offline":false
 },
 "newState":{
 "state":"PUBLISHED",
 "deleted":false,
 "enabled":true,
 "liveVersionAvailable":true,
 "offline":false
 },
 "stateChange":"PUBLISH",
 "nodeChanges":{
 "propertyNames":[
 "test:changed"
 ]
 },
 "cause":"SUBSTANTIAL_CHANGE"
}

Parameters

jsFunctionName: The name of a function in window

Example

registerDocumentChangeListenerFunction('sophoraDocumentChanged')

unregisterDocumentChangeListenerFunction

Unregisters a JavaScript function that is called when a document is changed.

Parameters

jsFunctionName: The name of a function in window

Example

unregisterDocumentChangeListenerFunction('sophoraDocumentChanged')

registerLockChangeListenerFunction

Registers a JavaScript function that is called when a document is locked or unlocked. The function will receive two parameters: A uuid as string and a boolean to indicate if the document is locked or not.

Parameters

jsFunctionName: The name of a function in window

Example

registerLockChangeListenerFunction('sophoraOnLockChangedEvent')

unregisterLockChangeListenerFunction

Unregisters a JavaScript function that is called when a document is locked or unlocked.

Parameters

jsFunctionName: The name of a function in window

Example

unregisterLockChangeListenerFunction('sophoraOnLockChangedEvent')

isUpdatable

Returns whether the document of the current editor is editable and can therefore be updated. Returns false if the browser is not associated with any document editor.

Parameters

No parameters.

Example

isUpdatable()

updateDocument

Updates the content in the editor (if an editor is available).

Parameters

document: The ISophoraDocument to update as JSON string

Example

updateDocument('<Document as JSON>')

saveDocument

Saves the given document. If the document has not been saved yet, idStem must not be null. In other cases, idStem can be null to keep the existing ID stem.

Returns the saved document as JSON string or null if the document has not been saved.

Parameters

  • document: The ISophoraDocument to save as JSON string
  • idStem: The ID stem the document shall achieve or null to keep the existing one

Example

saveDocument('<Document as JSON>', 'fashion-report')

The saveDocument method requires a JSON string that has to be created from a JavaScript object. For simple usage you can create a function in your application.

function saveSophoraDocument(documentObject, idStem) {
    var documentJson = JSON.stringify(documentObject);
    var savedDocumentJson = saveDocument(documentJson, idStem);
    return getSophoraDocumentOfJson(savedDocumentJson);
}

releaseDocument

Releases the document with the given UUID.

Returns false in case the operation was canceled.

Parameters

uuid: The UUID of the document as string

Example

releaseDocument('d70df790-17f1-44e2-b052-997235f6f7a5')

publishDocument

Publishes the document with the given UUID.

Returns false in case the operation was canceled.

Parameters

uuid: The UUID of the document as string

Example

publishDocument('d70df790-17f1-44e2-b052-997235f6f7a5')

setOfflineDocument

Sets the document with the given UUID offline.

Returns false in case the operation was canceled.

Parameters

uuid: The UUID of the document as string

Example

setOfflineDocument('d70df790-17f1-44e2-b052-997235f6f7a5')

deleteDocument

Deletes the document with the given UUID.

Returns false in case the operation was canceled.

Parameters

uuid: The UUID of the document as string

Example

deleteDocument('d70df790-17f1-44e2-b052-997235f6f7a5')

restoreDocument

Restores the document with the given UUID.

Returns false in case the operation was canceled.

Parameters

uuid: The UUID of the document as string

Example

restoreDocument('d70df790-17f1-44e2-b052-997235f6f7a5')

cloneDocument

Clones the document with the given UUID.

Returns the UUID of the clone as string or null if the document could not be cloned (e.g. the editor was dirty and the user declined the save).

Parameters

  • uuid: The UUID of the document to clone as string
  • structureNodeUUID: UUID of the target structure node as string

Example

cloneDocument('d70df790-17f1-44e2-b052-997235f6f7a5', '0c03b298-3e68-47e6-9a0f-c4b84887b3ba')

Check User Role and Pemissions via JavaScript

If an external web application is integrated in the DeskClient via 'Tools' or browser tab, it can execute checks on the users role and permissions via JavaScript functions or hyperlinks. The following checks also work within the preview view of a document inside the DeskClient.

userHasRole

Returns true if the user has the role with the given role id, else false.

Parameters

roleId: The role ID (which is the external ID) as string

Example

userHasRole('057336b7-e41a-378d-971c-37dfe8b19af0')

userHasStructureNodePermission

Returns true if the user has the given structure node permission on the specified structure node, else false.

Parameters

  • structureNodeUuid: The UUID of the structure node as string
  • structureNodePermission: The structure node permission as string

Example

userHasStructureNodePermission('e40a400a-38d9-4b3b-95b6-2de2a1228892', 'editStructure')

userHasDocumentPermissionByNodeType

Returns true if the user has the given document permission for the specified node type and structure node, else false.

Parameters

  • nodeTypeName: The node type name as string
  • documentPermission: The document permission as string
  • structureNodeUuid: The UUID of the structure node or null to specify any structure node as string

Example

userHasDocumentPermissionByNodeType('sophora-nt:message', 'read', 'e40a400a-38d9-4b3b-95b6-2de2a1228892')

userHasDocumentPermissionByNode

Returns true if the user has the given document permission on the specified document, else false.

Parameters

  • document: The ISophoraDocument as JSON string
  • documentPermission: The document permission as string

Example

userHasDocumentPermissionByNode('<Document as JSON>', 'read')

userHasProposalSectionPermission

Returns true if the user has the given proposal permission for the given proposal section, else false.

Parameters

  • proposalPermission: The proposal permission as string
  • proposalSectionUuid: The uuid of the proposal section as string

Example

userHasProposalSectionPermission('readProposals', '6985297e-feaf-49e2-a225-f3b7a5113c32')

userHasTabPermission

Returns true if the user has the given tab permission for the given tab, else false.

Parameters

  • tabName: The tab name as string
  • tabPermission: The wanted tab permission as string

Example

userHasTabPermission('base', 'readTab')

userHasSystemPermission

Returns true if the user has the given system permission, else false.

Parameters

systemPermission: The system permission as string

Example

userHasSystemPermission('administrator')

Last modified on 1/13/21

The content of this page is licensed under the CC BY 4.0 License. Code samples are licensed under the MIT License.

Icon