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.
getDocument
Returns the document of the current editor as JSON string or null if the browser is not associated with any document editor.
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);
}
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);
}
getDocumentStateImageIdentifierByUuid
Returns the identifier for the state image of the document with the given UUID.
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.
getSelectValueListByExternalIdForStructurePath
Returns a list of select values documents as JSON string.
Parameters
externalId: The ExternalID of the select values document to convert to JSON stringstructure path: The path of the structure node to search for select values in
Example
getSelectValueListByExternalIdForStructurePath('751c382b-bed1-475e-8ec8-29e70d4c77f7', '/system')
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
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).
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"
}
unregisterDocumentChangeListenerFunction
Unregisters a JavaScript function that is called when a document is changed.
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.
unregisterLockChangeListenerFunction
Unregisters a JavaScript function that is called when a document is locked or unlocked.
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.
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: TheISophoraDocumentto save as JSON stringidStem: The ID stem the document shall achieve ornullto 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.
publishDocument
Publishes the document with the given UUID.
Returns false in case the operation was canceled.
setOfflineDocument
Sets the document with the given UUID offline.
Returns false in case the operation was canceled.
deleteDocument
Deletes the document with the given UUID.
Returns false in case the operation was canceled.
restoreDocument
Restores the document with the given UUID.
Returns false in case the operation was canceled.
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 stringstructureNodeUUID: 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.
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 stringstructureNodePermission: The structure node permission as string
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 stringdocumentPermission: The document permission as stringstructureNodeUuid: The UUID of the structure node ornullto 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: TheISophoraDocumentas JSON stringdocumentPermission: The document permission as string
userHasProposalSectionPermission
Returns true if the user has the given proposal permission for the given proposal section, else false.
Parameters
proposalPermission: The proposal permission as stringproposalSectionUuid: The uuid of the proposal section as string