DS Server

Javascript: CommentCollection.addAtPosition Method

Method|Introduced in 30.0

Description

Creates a comment with the specified comment string, start position and length.

Syntax

<void> CommentCollection.addAtPosition(<string> comment, <number> start, <number> length, [<AddCommentCallback> callback], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
comment

The comment string.

start

The index (one-based) of the first character which belongs to the comment.

length

The number of characters which belong to the comment.

callback

Optional. Receives the result of the add operation.

errorCallback

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

Examples

The following example demonstrates CommentCollection.addAtPosition in a practical document-editing workflow. It creates a comment with the specified comment string, start position and length.

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

TXTextControl.textParts.getMainText(function(mainText) {
    const comments = mainText.comments;
    comments.addAtPosition(
        "Please review this section.",
        1,
        5,
        function(response) {
            if (!response) {
                console.warn("No comment callback data was returned.");
                return;
            }
            
            console.log("add at position result:", response);
        },
        onTxError
    );
}, onTxError);