user_name property

FieldUserName.user_name property

Gest or sets the current user’s name.

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

@user_name.setter
def user_name(self, value: str):
    ...

Examples

Shows how to use the USERNAME field.

doc = aw.Document()
# Create a UserInformation object and set it as the source of user information for any fields that we create.
user_information = aw.fields.UserInformation()
user_information.name = 'John Doe'
doc.field_options.current_user = user_information
builder = aw.DocumentBuilder(doc=doc)
# Create a USERNAME field to display the current user's name,
# taken from the UserInformation object we created above.
field_user_name = builder.insert_field(field_type=aw.fields.FieldType.FIELD_USER_NAME, update_field=True).as_field_user_name()
self.assertEqual(user_information.name, field_user_name.result)
self.assertEqual(' USERNAME ', field_user_name.get_field_code())
self.assertEqual('John Doe', field_user_name.result)
# We can set this property to get our field to override the value currently stored in the UserInformation object.
field_user_name.user_name = 'Jane Doe'
field_user_name.update()
self.assertEqual(' USERNAME  "Jane Doe"', field_user_name.get_field_code())
self.assertEqual('Jane Doe', field_user_name.result)
# This does not affect the value in the UserInformation object.
self.assertEqual('John Doe', doc.field_options.current_user.name)
doc.update_fields()
doc.save(file_name=ARTIFACTS_DIR + 'Field.USERNAME.docx')

See Also