class ChangeItem
A class representing a change event on a SharePoint item, extending the base Change class with item-specific properties like activity type, content type, and sharing information.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/changes/item.py
7 - 45
moderate
Purpose
ChangeItem represents a change log entry for SharePoint items, providing access to metadata about what changed on an item including the type of activity performed, content type information, and details about sharing actions (who shared and with whom). It is used to track and query changes made to SharePoint list items or documents.
Source Code
class ChangeItem(Change):
"""A change on an item."""
@property
def activity_type(self):
"""
Returns activity type defined in ChangeActivityType
:rtype: str or None
"""
return self.properties.get("ActivityType", None)
@property
def content_type_id(self):
"""
Specifies an identifier for the content type
"""
return self.properties.get("ContentTypeId", ContentTypeId())
@property
def shared_by_user(self):
"""Return the sharedBy User Information in sharing action for change log."""
return self.properties.get("SharedByUser", SharedWithUser())
@property
def shared_with_users(self):
"""Returns the array of users that have been shared in sharing action for the change log."""
return self.properties.get(
"SharedWithUsers", ClientValueCollection(SharedWithUser)
)
def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"ContentTypeId": self.content_type_id,
"SharedByUser": self.shared_by_user,
"SharedWithUsers": self.shared_with_users,
}
default_value = property_mapping.get(name, None)
return super(ChangeItem, self).get_property(name, default_value)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Change | - |
Parameter Details
__init__: Inherits constructor from parent Change class. The exact parameters are not visible in this code but typically include change metadata from SharePoint's change log API.
Return Value
Instantiation returns a ChangeItem object that provides property-based access to change metadata. Properties return specific types: activity_type returns a string or None, content_type_id returns a ContentTypeId object, shared_by_user returns a SharedWithUser object, and shared_with_users returns a ClientValueCollection of SharedWithUser objects.
Class Interface
Methods
@property activity_type(self) -> str | None
property
Purpose: Returns the type of activity that caused this change (e.g., Add, Update, Delete, Share)
Returns: A string representing the activity type from ChangeActivityType enumeration, or None if not available
@property content_type_id(self) -> ContentTypeId
property
Purpose: Retrieves the content type identifier for the changed item
Returns: A ContentTypeId object representing the content type of the item, or an empty ContentTypeId if not available
@property shared_by_user(self) -> SharedWithUser
property
Purpose: Gets information about the user who performed a sharing action
Returns: A SharedWithUser object containing user information, or an empty SharedWithUser if not a sharing action
@property shared_with_users(self) -> ClientValueCollection[SharedWithUser]
property
Purpose: Retrieves the collection of users with whom the item was shared
Returns: A ClientValueCollection containing SharedWithUser objects for each user the item was shared with, or an empty collection if not a sharing action
get_property(self, name: str, default_value=None) -> Any
Purpose: Retrieves a property value by name with support for default values and property mapping
Parameters:
name: The name of the property to retrieve (e.g., 'ActivityType', 'ContentTypeId', 'SharedByUser', 'SharedWithUsers')default_value: Optional default value to return if property is not found. If None, uses internal property mapping for known properties
Returns: The property value if found, the mapped default object for known properties, or the provided default_value
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
properties |
dict | Inherited from parent Change class. Dictionary containing the raw property data from SharePoint's change log | instance |
Dependencies
office365.runtime.client_value_collectionoffice365.sharepoint.changes.changeoffice365.sharepoint.contenttypes.content_type_idoffice365.sharepoint.sharing.shared_with_user
Required Imports
from office365.runtime.client_value_collection import ClientValueCollection
from office365.sharepoint.changes.change import Change
from office365.sharepoint.contenttypes.content_type_id import ContentTypeId
from office365.sharepoint.sharing.shared_with_user import SharedWithUser
Usage Example
# Assuming you have a SharePoint context and change collection
from office365.sharepoint.changes.change_item import ChangeItem
# Typically obtained from a change query, not instantiated directly
# change_item = ctx.web.get_changes(query).execute_query()[0]
# Access change properties
activity = change_item.activity_type # e.g., 'Add', 'Update', 'Delete'
content_type = change_item.content_type_id # ContentTypeId object
shared_by = change_item.shared_by_user # SharedWithUser object
shared_with = change_item.shared_with_users # Collection of SharedWithUser objects
# Use get_property for flexible access
activity_via_method = change_item.get_property('ActivityType')
content_type_via_method = change_item.get_property('ContentTypeId')
Best Practices
- ChangeItem objects are typically obtained from SharePoint change queries, not instantiated directly by users
- Use property accessors (activity_type, content_type_id, etc.) for type-safe access to change metadata
- The get_property method provides a fallback mechanism with default values for missing properties
- Properties return default empty objects (ContentTypeId, SharedWithUser, ClientValueCollection) rather than None when data is missing
- This class is read-only and represents historical change data; it should not be modified
- Always check if activity_type is None before using it, as not all changes have an activity type
- The shared_by_user and shared_with_users properties are only populated for sharing-related activities
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class Change 80.5% similar
-
class ChangeField 75.8% similar
-
class ChangeGroup 73.6% similar
-
class ChangeContentType 72.2% similar
-
class ChangeFile 71.0% similar