User post-registration script
This example shows a User post-registration web script that is executed after a new user is added to Sitecore Content Hub. It adds the user to a specific user group if the external provider is Google.
-
Configure the user groups or profiles required during the pre-registration process.
-
Create a user group called Google.
-
Ensure schema properties align with the script logic for pre-registration workflows.
Script
Script explanation
This section steps through the script in execution order, explaining each part. The numbered items describe the sequence, not instructions to perform.
-
Include necessary libraries.
-
Check the external user provider. If the provider is not
Google, the script exits. -
Create a query that gets the Google user group.
-
Execute the query to get the Google group ID.
-
If the user group cannot be found, throw an
InvalidOperationException. -
Get the user's user group relation.
-
Add the Google group to the user's object via the user group relation.
-
Save the user entity.
Setup
-
Create, publish, and enable the User post-registration script.