Component script is the core Python script that dynamically determines the behavior of each and every Page and Form for specific component. Script is automatically executed each time a Component Page is shown to the user.

Script uses properties provided via clr and system libraries to check different conditions (for example, a value of a field, or wherever the component data instance is pre-existing or just being created).

Typical examples of the Component Script use include:

import clr

# If context.Model.Id equals zero, the instance is not yet saved
if (context.Model.Id == 0):
# So we disable the SendToPublish (internal name) button
    context.Properties.SendToPublish.Disabled = True
else:
# Otherwise we enable the SendToPublish (internal name) button 
    context.Properties.SendToPublish.Disabled = False
# If SendToPublish workflow has been started and has reached the Confirmation (2) stage 
# We will navigate UI to the Component's page with the system name ConfirmationApprove
if (context.Workflows["SendToPublish"].State.value__  == 2):
    context.Properties.ApproveActions.WorkflowInstanceId = context.Workflows["SendToPublish"].WorflowInstanceId
    context.Commands.ChangePageByName("ConfirmationApprove")

The following variables/commands are available for the Component scripts

var formContext = new ApplicationContextWrapper()
                    {
                        Model = dataModel,
                        DataModel = DataModelContexts,
                        Form = formWrapper,
                        Commands = ApplicationCommandService,
                        Workflows = _workflowStates
                    };

026.png

Display script needs to use Python version 3.0 or later. For more information, please refer to