Script properties
In Sitecore Content Hub, all types of scripts have access to 2 main objects: MClient
and Context
. Both MClient and Context objects provide users with a collection of useful properties.
MClient properties
MClient properties are available for all types of scripts. They allow users to manipulate data in Content Hub (e.g. data sources, entities, entity definitions, policies, scripts, users) and other functionalities like querying and logging through different clients.
The following table summarizes the available MClient properties:
Property | Type |
---|---|
Commands | Stylelabs.M.Sdk.Clients.ICommandsClient |
Cultures | Stylelabs.M.Sdk.Clients.ICultureClient |
DataSourceFactory | Stylelabs.M.Sdk.Factories.IDataSourceFactory |
DataSources | Stylelabs.M.Sdk.Clients.IDataSourcesClient |
Entities | Stylelabs.M.Sdk.Clients.IEntitiesClient |
EntityDefinitions | Stylelabs.M.Sdk.Clients.IEntityDefinitionsClient |
EntityFactory | Stylelabs.M.Sdk.Factories.IEntityFactory |
Jobs | Stylelabs.M.Sdk.Clients.IJobsclient |
Logger | Stylelabs.M.Sdk.Contracts.Logging.ILogger |
Notifications | Stylelabs.M.Sdk.Clients.INotificationsClient |
Package | Stylelabs.M.Sdk.Clients.IPackageClient |
Policies | Stylelabs.M.Sdk.Clients.IPoliciesClient |
Querying | Stylelabs.M.Sdk.Clients.IQueryingClient |
Scripts | Stylelabs.M.Sdk.Clients.IScriptsClient |
Settings | Stylelabs.M.Sdk.Clients.ISettingsClient |
Users | Stylelabs.M.Sdk.Clients.IUsersClient |
For more information about clients or factories, please refer to the SDK API reference.
Context properties
Context properties are the different context variables that are accessible by scripts. Each script type has specific context properties. The following section defines the context properties for each script type.
For a descriptive list of script types, please refer to the script types section.
User sign-in scripts
The following table contains the context properties available for User sign-in scripts.
Property | Type | Description |
---|---|---|
AuthenticationSource | M.Base.Scripting.Users.AuthenticationSource | This property contains the source of registration of the user, which can be internal (Content Hub) or external (an external provider). Possible values:
|
User | M.Sdk.Contracts.Base.IEntity | This property contains the entity object representing the signed-in user. |
ExternalInfo | ExternalUserInfo | This property contains the information about the user that the external provider supplies.ExternalUserInfo properties:
|
Warning
ExternalInfo
is only used when the AuthenticationSource
is External
.
For more information about the context properties, please refer to the API reference guide.
User pre-registration scripts
The following table contains the context properties available for User registration scripts.
Property | Type | Description |
---|---|---|
AuthenticationSource | M.Base.Scripting.Users.AuthenticationSource | This property contains the source of registration of the user, which can be internal (Content Hub) or external (an external provider). Possible values:
|
Username | string | This property contains the username of the created user. |
string | This property contains the email of the created user. | |
Culture | System.Globalization.CultureInfo | This property contains the culture information of the created user. |
For more information about the context properties, please refer to the API reference guide.
User post-registration scripts
The following table contains the context properties available for User registration scripts.
Property | Type | Description |
---|---|---|
AuthenticationSource | M.Base.Scripting.Users.AuthenticationSource | This property contains the source of registration of the user, which can be internal (Content Hub) or external (an external provider). Possible values:
|
User | M.Sdk.Contracts.Base.IEntity | This property contains the entity object representing the signed-in user. |
ExternalInfo | ExternalUserInfo | This property contains the information about the user that the external provider supplies.ExternalUserInfo properties:
|
Warning
ExternalInfo
is only used when the AuthenticationSource
is External
.
For more information about the context properties, please refer to the API reference guide.
Metadata processing script
The following table contains the context properties available for Metadata processing scripts.
Property | Type | Description |
---|---|---|
File | M.Sdk.Contracts.Processing.IFile | This property contains the File entity that is being processed. IFile properties:
|
Asset | Stylelabs.M.Sdk.Contracts.Base.IEntity | This property contains the entity object representing the asset associated with the File entity being processed. |
MetadataProperties | IReadOnlyDictionary<string, JToken> | This property contains the available metadata. The metadata properties depend on the processed file. |
For more information about the context properties, please refer to the API reference guide.
Action scripts
For Action scripts, the context properties depend on the execution source of the script. The execution source is the method by which the script is called. The context properties differ according to the following use cases:
Web Api: When the script is called by a Web Api (REST).
Note
In this case,
ExecutionSource
is equal toWebApi
.External Action: When the script is called by an external action from a page component.
Note
In this case,
ExecutionSource
is equal toExternalAction
orMassEdit
. It is set toMassEdit
when the Action script is called from the mass-edit menu.Triggers: The context properties for triggers depend on their execution type: In Process or In Background (Out of process).
In Background: When the script is called by a trigger in background.
Note
In this case,
ExecutionSource
is equal toTrigger
andExecutionType
is equal toOutOfProcess
.In Process: When the script is called by a trigger in process.
Note
In this case,
ExecutionSource
is equal toTrigger
andExecutionType
is equal toInProcess
.
The following table contains the context properties for each use case.
Property | Type | Description |
---|---|---|
ExecutionSource | M.Base.Scripting.Action.ExecutionSource | This property indicates the execution source of the script. Possible values:
|
ExecutionType | M.Base.Scripting.Action.ExecutionType | This property indicates the execution type of the script. Possible values:
|
TargetId | Nullable System.Int64 | This property contains the Id of the entity being processed by the script. |
TargetType | M.Base.Scripting.Action.TargetType | This property indicates the type of the entity being processed by the script. Possible values:
|
Note
When a script is called from the mass-edit menu (ExecutionSource == MassEdit
), the entities involved in the mass-edit action are processed by the script one at a time. For each iteration, TargetId
contains the Id if the entity being currently processed.
Property | Type | Description |
---|---|---|
ExecutionSource | M.Base.Scripting.Action.ExecutionSource | This property indicates the execution source of the script. Possible values:
|
ExecutionType | M.Base.Scripting.Action.ExecutionType | This property indicates the execution type of the script. Possible values:
|
TargetId | Nullable System.Int64 | This property contains the Id of the entity being processed by the script. |
TargetType | M.Base.Scripting.Action.TargetType | This property indicates the type of the entity being processed by the script. Possible values:
|
PropertyBag | M.Base.Scripting.Action.IPropertyBag | A key-value property bag that stores user defined properties across multiple scripts. |
Note
Property bags are available across scripts. Each property bag is specific to a combination of events and conditions.
Note
The scripts called by the same trigger have access to the same property bag.
Note
If several triggers are fired following the same event (e.g Entity creation) and the same conditions (e.g. Entity definition is Asset), the scripts called by any those triggers have access to the same property bag.
Property | Type | Description |
---|---|---|
ExecutionSource | M.Base.Scripting.Action.ExecutionSource | This property indicates the execution source of the script. Possible values:
|
ExecutionType | M.Base.Scripting.Action.ExecutionType | This property indicates the execution type of the script. Possible values:
|
TargetId | Nullable System.Int64 | This property contains the Id of the entity being processed by the script. |
TargetType | M.Base.Scripting.Action.TargetType | This property indicates the type of the entity being processed by the script. Possible values:
|
PropertyBag | M.Base.Scripting.Action.IPropertyBag | A key-value property bag that stores user defined properties across multiple scripts. |
Target | System.Object | This property contains the entity related to the triggering event. |
ExecutionEvent | M.Base.Scripting.Action.ExecutionEvent | This property indicates the execution event of the trigger. Possible values:
|
ExecutionPhase | M.Base.Scripting.Action.ExecutionPhase | This property indicates the execution phase in which the script is executed. Possible values:
|
ChangeTracker | IChangeTracker | This property tracks the changes that have occured on the entity. |
Important
Property bags are available across scripts. Each property bag is specific to a combination of events and conditions.
Note
The scripts called by the same trigger have access to the same property bag.
Note
If several triggers are fired following the same event (e.g Entity creation) and the same conditions (e.g. Entity definition is Asset), the scripts called by any of those triggers have access to the same property bag.
For more information about the context properties, please refer to the API reference guide.
Can we improve this article ? Provide feedback