DS Server

Javascript: DocumentTargetCollection.add Method

Method|Introduced in 28.0

Description

Adds a new document target to the collection.

Syntax

<void> DocumentTargetCollection.add(<string> targetName, [<RequestDocumentTargetCallback> callback], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
targetName

The target's name.

callback

Optional. Receives the added document target or null if no target could be added.

errorCallback

Optional. Is called when the operation failed with an error.

Examples

The following example demonstrates DocumentTargetCollection.add in a practical document-editing workflow. It adds a new document target to the collection.

function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

TXTextControl.textParts.getMainText(function(mainText) {
    const documentTargets = mainText.documentTargets;
    documentTargets.add(
        "InvoiceDetails",
        function(result) {
            if (!result) {
                console.warn("No document target was returned.");
                return;
            }
            
            console.log("add result:", result);
        },
        onTxError
    );
}, onTxError);