--- title: "Script Use Cases" slug: "script-use-cases" description: "This article provides use cases for Scripts in Content Types. " updated: 2026-07-09T18:00:34Z published: 2026-07-09T18:00:34Z canonical: "www.civicplus.help/script-use-cases" --- > ## Documentation Index > Fetch the complete documentation index at: https://www.civicplus.help/llms.txt > Use this file to discover all available pages before exploring further. # Script Use Cases This article provides use cases for [Scripts in Content Types](/civicplus-help-center/docs/create-scripts-for-a-content-type). ## Debugging: Write the Context to a Field If you want to understand your data structure and the context object, you can just write it to a string field. ```plaintext ctx.data.debug.iv = JSON.stringify(ctx, null, 2);// Tell Squidex that the content should be replaced.replace(); ``` --- ## Do Not Return Sensitive Information When Queried by Client ```plaintext if (ctx.isClient) { // ctx Variable contains all Context informationctx.data.password.iv = '********';// Tell Squidex that the content should be replaced.replace(); } ``` --- ## Do Not Allow the Client to Set Fields ```plaintext if (ctx.isClient && ctx.data.password.iv) {// Tell Squidex to return a 403 (Forbidden)disallow();} ``` --- ## Ensure Two Fields Have the Same Value ```plaintext if (data.password.iv !== data.passwordConfirm.iv) {// Tell Squidex to return a 400 (Bad Request)reject('Passwords must be the same');} ``` --- ## Ensure Only a Specific User Can Publish Content ```plaintext if (ctx.operation === 'Published' && ctx.user.email !== 'content@master.com') {// Reject the call if the publisher has another email address.reject('You are not allowed to publish the content');} ``` --- ## Compute Field From Other Values **Store in a separate field if another field has a valid value:** ```plaintext ctx.data.hasPassword = { iv: !!ctx.data.password.iv };// Tell Squidex that the content should be replaced.replace(); ``` **Calculate the slug for a content title automatically:** ```plaintext ctx.data.slug.iv = slugifx(ctx.data.title.iv);// Tell Squidex that the content should be replaced.replace(); ``` **Calculate the number of words in a Markdown field:** ```plaintext ctx.data.wordCount.iv = wordCount(markdown2Text(ctx.data.html.iv)));// Tell Squidex that the content should be replaced.replace(); ``` **Calculate the number of characters in an HTML field:** ```plaintext ctx.data.characterCount.iv = characterCount(html2Text(ctx.data.html.iv)));// Tell Squidex that the content should be replaced.replace(); ``` --- ## Enrich Your Content with Data From External Services We can use the getJSON function to enrich the content with data from external services. This example is a little bit more complicated than the other examples above, but let's jump into the code first. ```plaintext var url = 'https://jsonplaceholder.typicode.com/todos/1';var headers = {ApiKey: 'secret'};getJSON(url, function(result) {data.title.iv = result.title;// Tell Squidex that the content should be replaced.replace();}, headers);// I am done ``` When we make an asynchronous call to another service or content, the script engine cannot stop the script automatically. Therefore, it is very important to finish the script with a call to replace(), even if we do not make a change to the content data. --- ## Resources - [Create Scripts for a Content Type](/civicplus-help-center/docs/create-scripts-for-a-content-type) - [Variables for Scripts](/civicplus-help-center/docs/variables-for-scripts) - [Script Methods](/civicplus-help-center/docs/script-methods) Hypertext Markup Language. The language used to define the content of the site in a structurally meaningful manner.