This article will show you how to create scripts for a Content Type. Scripts can be used for many different purposes such as validation and providing additional security or permissions on a specific content type.
The HCMS provides many generic, easy-to-use options for validation and security such as permission sets, roles, and workflows. Scripts can be used to handle gaps and address specific use cases that other areas of the HCMS do not address. Scripts can provide more specific controls that can be set for a given field, when certain information is added to or missing from a field, or even for a single user.
Example Uses of Scripts
While the options for scripts are endless, here are some examples that could get you started:
- If you did not fill out this field, you could use a script to autofill the content for a field
- You could use a script to fill out a field every time an item is created. An example of this is on the Department content type (for newer HCMS applications) where Staff Directory information is auto-filled each time a Department content item is created
- Only a single person could create something or update a field (an “Approval” field for example)
- Verify whether something was filled out or not
- Only publish if certain criteria are met (such as an item can only be published if the above-mentioned “Approval” field has been approved by a single individual)
- Prevent someone from deleting an item
Instructions
- Select Content Types on the left-hand side and select your desired Content Type
- Navigate to the Scripts tab
- Add Scripts to Query, Create, Change, Delete, and/or Update
Note: There are some restrictions for scripts which include:- You cannot include external libraries.
- You cannot make calls to external services except getJSON.
- Scripts will timeout after 200ms of CPU execution.
- Scripts will timeout after 5sec of total execution, e.g. waiting for external services with getJSON.
Learn more about script variables, methods, and use cases.
- Query: These scripts are executed whenever a content item is queried with the API (such as from your CivicEngage Evolve website), but not when queried in the HCMS user interface.
- Create: Scripts are executed before a content item is created.
- Change: Scripts are executed before the status of a content item is changed. When you use scheduling to change the status of a content item in the future, the script is called just before the status is changed and not when you schedule it. When the script fails or rejects the change, your scheduling could be impacted.
- Delete: Scripts are executed before a content item is deleted.
- Update: Scripts are executed before a content item is updated.
- Click Save
Comments
Let us know what was helpful or not helpful about the article.0 comments
Please sign in to leave a comment.