display_result property

Field.display_result property

Gets the text that represents the displayed field result.

@property
def display_result(self) -> str:
    ...

Remarks

The Document.update_list_labels() method must be called to obtain correct value for the FieldListNum, FieldAutoNum, FieldAutoNumOut and FieldAutoNumLgl fields.

Examples

Shows how to get the real text that a field displays in the document.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

builder.write("This document was written by ")
field_author = builder.insert_field(aw.fields.FieldType.FIELD_AUTHOR, True).as_field_author()
field_author.author_name = "John Doe"

# We can use the "display_result" property to verify what exact text
# a field would display in its place in the document.
self.assertEqual("", field_author.display_result)

# Fields do not maintain accurate result values in real-time.
# To make sure our fields display accurate results at any given time,
# such as right before a save operation, we need to update them manually.
field_author.update()

self.assertEqual("John Doe", field_author.display_result)

doc.save(ARTIFACTS_DIR + "Field.display_result.docx")

See Also