Part II: Prototype Contentstack Update Webhook Handler .NET Azure Function to Set Field Values for Validation

This blog post presents code for a prototype .NET Azure function that handles entry update webhooks from the Contentstack SaaS headless CMS to set the value of a field in the entry that presents messages to the CMS user. Specifically, this example ensures that two date fields exist and contain values, and that the value in the second field follows the first chronologically.

For background information, see this previous blog post:

Warning: Updating an entry from an update webhook handler triggers the CMS to invoke the update webhook and hence the handler again, leading to potential infinite recursion.

This prototype uses two techniques to avoid infinite recursion. First, it uses a field to store the time at which this logic last applied to the entry. If that time is close to the most recent update time for that entry, then it assumes that that this logic performed that update and aborts its logic that could update the entry again. Second, if the value it would set to the field would not change, then it aborts its logic that would update the entry again.

Because CMS users should not modify the content of the field used in this example and the system can restore that value if they do, the operations of this handler should not interfere with user activities except that the UI may prompt the user to load or compare a new version after it applies the validation after a save operation.

This solution depends on the HTTP request handler described in a previous blog post:

You may want to use field visibility rules to hide the date that indicates when the logic last ran for the entry.

This solution is intentionally procedural and hard-coded to demonstrate logic and programming techniques.

3 thoughts on “Part II: Prototype Contentstack Update Webhook Handler .NET Azure Function to Set Field Values for Validation

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: