class ListItemFormUpdateValue
A class representing the properties and value of a SharePoint list item field, used for updating list item form values with validation support.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/listitems/form_update_value.py
7 - 35
moderate
Purpose
This class encapsulates the data structure required for updating SharePoint list item fields through form operations. It handles field names, values, validation exceptions, and error codes. The class extends ClientValue and provides special serialization for lookup fields and datetime values, making it suitable for SharePoint REST API operations involving list item updates.
Source Code
class ListItemFormUpdateValue(ClientValue):
"""Specifies the properties of a list item field and its value."""
def __init__(self, name=None, value=None, has_exception=None, error_code=None):
"""
:param str name: Specifies the field internal name for a field.
:param str value: Specifies a value for a field.
:param bool has_exception: Specifies whether there was an error result after validating the value for the field
param int ErrorCode: Specifies the error code after validating the value for the field
"""
super(ListItemFormUpdateValue, self).__init__()
self.FieldName = name
self.FieldValue = value
self.HasException = has_exception
self.ErrorCode = error_code
def to_json(self, json_format=None):
json = super(ListItemFormUpdateValue, self).to_json(json_format)
if isinstance(self.FieldValue, FieldLookupValue):
json["FieldValue"] = (
"[{" + "'Key':'{0}'".format(self.FieldValue.LookupValue) + "}]"
)
elif isinstance(self.FieldValue, datetime):
json["FieldValue"] = self.FieldValue.isoformat()
return json
@property
def entity_type_name(self):
return "SP.ListItemFormUpdateValue"
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
ClientValue | - |
Parameter Details
name: The internal name of the SharePoint field being updated. This should match the field's internal name in the SharePoint list schema (e.g., 'Title', 'Modified', 'CustomField'). Can be None if not yet specified.
value: The value to set for the field. Can be a string, FieldLookupValue object for lookup fields, datetime object for date/time fields, or other appropriate types depending on the field type. Can be None if not yet specified.
has_exception: Boolean flag indicating whether validation of the field value resulted in an error. True if there was a validation exception, False otherwise. Can be None if validation has not been performed.
error_code: Integer error code returned after field value validation. Provides specific error information when has_exception is True. Can be None if no error occurred or validation has not been performed.
Return Value
Instantiation returns a ListItemFormUpdateValue object that encapsulates field update information. The to_json() method returns a dictionary representation suitable for JSON serialization, with special handling for FieldLookupValue objects (formatted as SharePoint lookup syntax) and datetime objects (converted to ISO format strings). The entity_type_name property returns the string 'SP.ListItemFormUpdateValue'.
Class Interface
Methods
__init__(self, name=None, value=None, has_exception=None, error_code=None)
Purpose: Initializes a new ListItemFormUpdateValue instance with field name, value, and validation status
Parameters:
name: The internal name of the SharePoint field (str or None)value: The value to set for the field (str, FieldLookupValue, datetime, or other types, or None)has_exception: Boolean indicating if validation resulted in an error (bool or None)error_code: Integer error code from validation (int or None)
Returns: None (constructor)
to_json(self, json_format=None) -> dict
Purpose: Serializes the object to a JSON-compatible dictionary with special handling for lookup and datetime values
Parameters:
json_format: Optional format parameter passed to parent class serialization (type and usage determined by parent ClientValue class)
Returns: Dictionary representation of the object suitable for JSON serialization, with FieldValue formatted appropriately for lookup fields (as SharePoint lookup syntax string) and datetime fields (as ISO format string)
@property entity_type_name(self) -> str
property
Purpose: Returns the SharePoint entity type name for this class
Returns: The string 'SP.ListItemFormUpdateValue' representing the SharePoint entity type
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
FieldName |
str or None | The internal name of the SharePoint field being updated | instance |
FieldValue |
str, FieldLookupValue, datetime, or other types, or None | The value to be set for the field, with type depending on the field type in SharePoint | instance |
HasException |
bool or None | Flag indicating whether field value validation resulted in an error | instance |
ErrorCode |
int or None | Error code returned from field value validation when HasException is True | instance |
Dependencies
datetimeoffice365
Required Imports
from datetime import datetime
from office365.runtime.client_value import ClientValue
from office365.sharepoint.fields.lookup_value import FieldLookupValue
Usage Example
from datetime import datetime
from office365.sharepoint.listitems.form_update_value import ListItemFormUpdateValue
from office365.sharepoint.fields.lookup_value import FieldLookupValue
# Simple text field update
text_update = ListItemFormUpdateValue(
name='Title',
value='New Item Title',
has_exception=False,
error_code=None
)
# Date field update
date_update = ListItemFormUpdateValue(
name='DueDate',
value=datetime(2024, 12, 31),
has_exception=False,
error_code=None
)
# Lookup field update
lookup_value = FieldLookupValue()
lookup_value.LookupValue = '5'
lookup_update = ListItemFormUpdateValue(
name='AssignedTo',
value=lookup_value,
has_exception=False,
error_code=None
)
# Serialize to JSON for API call
json_data = text_update.to_json()
print(json_data)
# Get entity type name
type_name = text_update.entity_type_name
print(type_name) # Output: SP.ListItemFormUpdateValue
Best Practices
- Always set the 'name' parameter to match the exact internal field name in SharePoint, not the display name
- Use appropriate value types: FieldLookupValue for lookup fields, datetime objects for date/time fields, strings for text fields
- Check has_exception and error_code after validation operations to handle errors appropriately
- When working with lookup fields, ensure the FieldLookupValue object has the LookupValue property set to the target item ID
- The to_json() method automatically handles special formatting for lookup and datetime values, so no manual conversion is needed
- This class is typically used in collections when updating multiple fields at once in SharePoint list item operations
- Instantiate separate ListItemFormUpdateValue objects for each field being updated rather than reusing instances
- The class inherits from ClientValue, so it follows the Office365 library's serialization patterns for SharePoint operations
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class ListItemUpdateParameters 71.2% similar
-
class FieldLookupValue 69.7% similar
-
class ListItemVersionCollectionPosition 67.2% similar
-
class ListItemCreationInformation 67.1% similar
-
class ListHomeItem 66.9% similar