Track changes in word not workng for inline content controls if content controls are created using Aspose code

Hi Team,

We are facing using with Track changes in word. When we create content control in document programmatically using Aspose java code , and open the document in word and enable track changes and make changes in content control , then it is not working properly. It is not showing red lining to the data we have updated. It works fine for content controls created using word. Please check and help us.

Sample code used to create content control :

StructuredDocumentTag sdt1 = new StructuredDocumentTag(document, SdtType.PLAIN_TEXT, MarkupLevel.INLINE);
sdt1.removeAllChildren();
sdt1.appendChild(new Run(document, "Content control"));
documentBuilder.insertNode(sdt1);

Attaching word file for reference :

track_change_issue.zip (13.8 KB)

Please help.

@saurabh.arora The problem occurs because when you create StructuredDocumentTag, its property ShowingPlaceholderText is set to true. In your case you insert content into the StructuredDocumentTag so you should reset this flag to false. Try to modify your code like the following and let us know if this works for you:

StructuredDocumentTag sdt1 = new StructuredDocumentTag(document, SdtType.PLAIN_TEXT, MarkupLevel.INLINE);
sdt1.isShowingPlaceholderText(false);
sdt1.removeAllChildren();
sdt1.appendChild(new Run(document, "Content control"));

Hi Team,

Thanks for the response. The above code is working fine for all types of content control except date type. For date type tag it is showing ‘Click here to enter data’. Following is the code snippet.

public static void main(String[] args) throws Exception {
    Document document = new Document();
    com.aspose.words.License license = new com.aspose.words.License();
    license.setLicense("/home/hari/IdeaProject/sirion/api-service/target/classes/asposeLicence/aspose-licence");
    DocumentBuilder documentBuilder = new DocumentBuilder(document);
    StructuredDocumentTag contentTag = new StructuredDocumentTag(document, SdtType.DATE, MarkupLevel.INLINE);
    contentTag.isShowingPlaceholderText(false);
    contentTag.removeAllChildren();
    contentTag.setDateDisplayFormat("mm/dd/yyyy");

    // Paragraph nodes = new Paragraph(document);

    Run run = new Run(document);
    contentTag.setTag("1001");
    contentTag.setTitle("Date Tag");
    run.setText("Date Tag");

    contentTag.getChildNodes().add(run);
    // nodes.appendChild(run);
    // documentBuilder.a(nodes);
    documentBuilder.insertNode(contentTag);

    StructuredDocumentTag contentTag1 = new StructuredDocumentTag(document, SdtType.PLAIN_TEXT, MarkupLevel.INLINE);
    contentTag1.isShowingPlaceholderText(false);
    contentTag1.removeAllChildren();
    Run run1 = new Run(document);
    contentTag1.setTag("1002");
    contentTag1.setTitle("Plain Text");
    run1.setText("Plain Text");

    contentTag1.getChildNodes().add(run1);
    documentBuilder.insertNode(contentTag1);

    document.save("/home/hari/Documents/valnewdval.docx");
}

Attaching the document for reference.
valnewdval.zip (9.5 KB)

Please help

@saurabh.arora In case of using DATE structured document tag, you should use StructuredDocumentTag.setFullDate method to set its value. See the following code:

StructuredDocumentTag contentTag = new StructuredDocumentTag(document, SdtType.DATE, MarkupLevel.INLINE);
contentTag.isShowingPlaceholderText(false);
contentTag.setDateDisplayFormat("M/d/yyyy");
contentTag.setTag("1001");
contentTag.setTitle("Date Tag");
contentTag.removeAllChildren();

contentTag.setFullDate(new Date());

documentBuilder.insertNode(contentTag);