Set Properties on Content Approval in Sitecore Content Hub
Sitecore Content Hub provides you with the features and functionality to create a trigger, an action, and a respective script to enhance your customization and implement your business logic.
As we are aware, we can execute the Trigger, Action, and Script on the Save button of the content entity, but in case you want to update any field value example, date field values, once the author approves the content after final review, instead of the save button then we have to tweak our approach while setting up condition into the trigger.
As we know, triggers, actions, and scripts in Sitecore Content Hub are typically executed by clicking the Save button of a content entity. However, suppose you want to update a field, such as a date field, specifically when the author approves the content after the final review (rather than during draft, review, or version save). In that case, the trigger conditions need to be carefully configured.
The business requirement in this case is to capture the exact date and time when the author formally approves the content, rather than during any intermediate save or versioning action.
Step 1: Create a Date field in your Content Entity.
Step 2: If you are not familiar with the Sitecore Content Hub Script, Action, and Trigger, or how to write and execute them, see the blog post: Create Script, Action, and Trigger in Sitecore Content Hub
Step 3: Write the action script that retrieves the content ID and sets the date field value within the script logic. You can refer to the sample code below.
var entity = Context.Target as IEntity; var approvalDate = entity.ModifiedOn; entity.SetPropertyValue("Student_DateApproval", approvalDate);
Step 4: Create a Trigger, and under the Condition tab, apply the following condition to ensure the action and script are triggered when the Approve button is clicked.
Happy Sitecoreing 😊
Comments
Post a Comment