public class FieldUserInitials extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Retrieves the current user's initials.
Examples:
Shows how to use the USERINITIALS field.
Document doc = new Document();
// Create a UserInformation object and set it as the source of user information for any fields that we create.
UserInformation userInformation = new UserInformation();
userInformation.setInitials("J. D.");
doc.getFieldOptions().setCurrentUser(userInformation);
// Create a USERINITIALS field to display the current user's initials,
// taken from the UserInformation object we created above.
DocumentBuilder builder = new DocumentBuilder(doc);
FieldUserInitials fieldUserInitials = (FieldUserInitials) builder.insertField(FieldType.FIELD_USER_INITIALS, true);
Assert.assertEquals(userInformation.getInitials(), fieldUserInitials.getResult());
Assert.assertEquals(" USERINITIALS ", fieldUserInitials.getFieldCode());
Assert.assertEquals("J. D.", fieldUserInitials.getResult());
// We can set this property to get our field to override the value currently stored in the UserInformation object.
fieldUserInitials.setUserInitials("J. C.");
fieldUserInitials.update();
Assert.assertEquals(" USERINITIALS \"J. C.\"", fieldUserInitials.getFieldCode());
Assert.assertEquals("J. C.", fieldUserInitials.getResult());
// This does not affect the value in the UserInformation object.
Assert.assertEquals("J. D.", doc.getFieldOptions().getCurrentUser().getInitials());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.USERINITIALS.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getUserInitials()
Gets the current user's initials.
|
void |
setUserInitials(java.lang.String value)
Sets the current user's initials.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic java.lang.String getUserInitials()
Examples:
Shows how to use the USERINITIALS field.
Document doc = new Document();
// Create a UserInformation object and set it as the source of user information for any fields that we create.
UserInformation userInformation = new UserInformation();
userInformation.setInitials("J. D.");
doc.getFieldOptions().setCurrentUser(userInformation);
// Create a USERINITIALS field to display the current user's initials,
// taken from the UserInformation object we created above.
DocumentBuilder builder = new DocumentBuilder(doc);
FieldUserInitials fieldUserInitials = (FieldUserInitials) builder.insertField(FieldType.FIELD_USER_INITIALS, true);
Assert.assertEquals(userInformation.getInitials(), fieldUserInitials.getResult());
Assert.assertEquals(" USERINITIALS ", fieldUserInitials.getFieldCode());
Assert.assertEquals("J. D.", fieldUserInitials.getResult());
// We can set this property to get our field to override the value currently stored in the UserInformation object.
fieldUserInitials.setUserInitials("J. C.");
fieldUserInitials.update();
Assert.assertEquals(" USERINITIALS \"J. C.\"", fieldUserInitials.getFieldCode());
Assert.assertEquals("J. C.", fieldUserInitials.getResult());
// This does not affect the value in the UserInformation object.
Assert.assertEquals("J. D.", doc.getFieldOptions().getCurrentUser().getInitials());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.USERINITIALS.docx");
public void setUserInitials(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to use the USERINITIALS field.
Document doc = new Document();
// Create a UserInformation object and set it as the source of user information for any fields that we create.
UserInformation userInformation = new UserInformation();
userInformation.setInitials("J. D.");
doc.getFieldOptions().setCurrentUser(userInformation);
// Create a USERINITIALS field to display the current user's initials,
// taken from the UserInformation object we created above.
DocumentBuilder builder = new DocumentBuilder(doc);
FieldUserInitials fieldUserInitials = (FieldUserInitials) builder.insertField(FieldType.FIELD_USER_INITIALS, true);
Assert.assertEquals(userInformation.getInitials(), fieldUserInitials.getResult());
Assert.assertEquals(" USERINITIALS ", fieldUserInitials.getFieldCode());
Assert.assertEquals("J. D.", fieldUserInitials.getResult());
// We can set this property to get our field to override the value currently stored in the UserInformation object.
fieldUserInitials.setUserInitials("J. C.");
fieldUserInitials.update();
Assert.assertEquals(" USERINITIALS \"J. C.\"", fieldUserInitials.getFieldCode());
Assert.assertEquals("J. C.", fieldUserInitials.getResult());
// This does not affect the value in the UserInformation object.
Assert.assertEquals("J. D.", doc.getFieldOptions().getCurrentUser().getInitials());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.USERINITIALS.docx");
value - The current user's initials.java.lang.Exception