FieldListNum not shown in deletion all markup

Hello ,
We have have following code to put a FieldListNum in a word document and then delete them with revision. But we have few issues and want to clarify.

  • Why is the list num not visible?
  • Why we dont see a strikethrough for list num ‘All markup’?

Also attaching the output and expected output.

output 2.docx (17.5 KB)

expected.docx (26.0 KB)

package org.example;

import com.aspose.words.*;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);

        FieldListNum field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
        field.setStartingNumber("0");
        builder.writeln("Paragraph 1");
        doc.updateFields();
        Node[] nodes = doc.getChildNodes(0, true).toArray();
        doc.startTrackRevisions("Author");
        Arrays.stream(nodes).toList().forEach(com.aspose.words.Node::remove);
        doc.stopTrackRevisions();

        doc.save("output.docx");
    }
}

@mandeep.dfin

To address your questions regarding the visibility of the FieldListNum and the absence of strikethrough for the list number in the deletion markup, let’s break down the issues:

  1. Visibility of the List Number: The FieldListNum field may not be visible in the output document because the Document.updateFields() method needs to be called after making changes to the document. This method ensures that all fields are updated to reflect their current state. In your code, you are calling updateFields() before removing the nodes, which might not yield the expected results. You should call updateFields() after the revisions are made to ensure that the list numbers are correctly displayed.

  2. Strikethrough for List Number: The absence of a strikethrough for the list number in the “All markup” view could be due to how the FieldListNum is processed during the deletion. When you remove nodes from the document, the field itself may not be marked for deletion in a way that reflects a strikethrough. To ensure that the list number is marked for deletion, you might need to explicitly track revisions for the field itself or ensure that the field is properly updated before removal.

Here’s a modified version of your code that addresses these points:

package org.example;

import com.aspose.words.*;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);

        FieldListNum field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
        field.setStartingNumber("0");
        builder.writeln("Paragraph 1");

        // Start tracking revisions before updating fields
        doc.startTrackRevisions("Author");
        doc.updateFields(); // Update fields after inserting content

        // Remove nodes
        Node[] nodes = doc.getChildNodes(NodeType.PARAGRAPH, true).toArray();
        Arrays.stream(nodes).forEach(Node::remove);

        // Stop tracking revisions
        doc.stopTrackRevisions();

        doc.save("output.docx");
    }
}

In this code, the updateFields() method is called after inserting the content but before removing the nodes, which should help in ensuring that the list number is visible and properly marked for deletion.

If you continue to experience issues, consider checking the Aspose documentation for further details on handling fields and revisions, as there may be additional nuances specific to your use case.

Feel free to reach out if you have more questions or need further assistance!

same behavior with suggested change.

@mandeep.dfin
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-27758

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hello Alexey,
Thanks for reply back. Will this internal ticket address the both the question we have about FieldListNums.

  • Why is the list num not visible in deletion markup?
  • Why we don’t see a strikethrough for list num ‘All markup’?

@mandeep.dfin Yes, this is the same problem. We will investigate it and let you know once it is resolved and provide you more information.

1 Like