Web Script Components - Web Script Components - Alfresco - Alfresco Content Services - Alfresco/Alfresco-Content-Services/23.4/Alfresco-Content-Services/Develop/Reference/Web-Scripts/Web-Script-Framework/Web-Script-Components - 23.4 - 23.4

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License
ft:lastPublication
2026-04-22T22:35:19.567073
ft:locale
en-US

The Web Script Framework lets you create a web script using familiar technologies, such as scripting and template languages.

Each web script comprises only the following components:

  • A description document
  • An optional controller script
  • One or more FreeMarker response templates

Each component is implemented in its own file. The Web Script Framework dictates where the files are located and how they are named. This allows the framework to automatically locate and register web scripts without having to tell the framework where they are. In some cases, a web script can fall back to Java or rely on advanced Web Script Framework features where scripting alone cannot support the requirements of the web script.

Users of a web script only interact through the web script interface, which comprises its URI, HTTP method, and request/response document types. All of these are described in the web script description document, which is defined by the web script creator.

The Web Script Components with XML Descriptor Document, JavaScript, and FreeMarker

Web script description document

A web script description document is an XML file that describes the URI and HTTP method that initiates the web script. For example, the web script is given a short name and description, along with authentication and transactional needs. URI bindings are described as URI templates.

An example of a web script description document follows:

<webscript>
  <shortname>Blog Search Sample</shortname>
  <description>Sample that finds all blog entries whose content contains the specified search term</description>
   <url>/sample/blog/search?q={searchTerm}</url>
   <url>/sample/blog/search.atom?q={searchTerm}</url>
   <url>/sample/b/s?q={searchTerm}</url>
   <url>/sample/b/s.atom?q={searchTerm}</url>
   <format default="html">extension</format>
   <authentication>guest</authentication>
   <transaction>required</transaction>
</webscript>

The following table describes the available options that can be set for a web script in the .desc.xml file:

Option Description Notes
<shortname> An identifier for the web script, for referencing. For example: Reset User Password
<description> A short description of the web script, shown in listings. For example: Reset a user's password and send an e-mail confirmation
<url> A list of URL patterns the web script responds to. For example: /extras/modules/reset-user-password

Parameterized URL patterns can also be defined using curly braces to specify named parameters. For example: /slingshot/node/content{property}/{store_type}/{store_id}/{id}?a={attach?}, where {store_type}, {store_id}, and {id} are required named parameters.

A ? after the parameter name, such as {attach?}, marks it as optional.

<format> The requested format for the web script’s response. The following options are available:
  • extension: Format is requested using the URL’s file extension. For example: /webscript.json.
  • argument: Format is requested using a request parameter. For example: webscript?format=json.

You can specify the default format if none is configured, such as in the following example: <format default=”json”>extension</format> or <format default=”json”>argument</format>

<authentication> The required authentication to access the web script, defining who can call the script. The following options are available:
  • none: No authentication is required. It is a public endpoint.
  • user: An authenticated Alfresco user can access it.
  • admin: A user must be a member of the ALFRESCO_ADMINISTRATORS group to access it.
  • sysadmin: A user with permissions for performing system specific operations, without access to customer content, can access it.
<transaction> The transaction policy defining how the web script is executed within an Alfresco transaction. The following options are available:
  • none: The script does not run within a transaction.
  • required: The script runs within a transaction.
  • requiresnew: The script starts a new transaction, suspending any existing transaction.
Note: If a web script implements an API that uses the POST method but only requires read-only access, such as the Search API, define the transaction option as allow="readonly", such as in the following example: <transaction allow=”readonly”>required</transaction>. This configuration informs the Alfresco engine that the script is safe to run in read-only mode, enabling the API to function correctly.
<family> The label for grouping related web scripts. For example: Password
<lifecycle> The status or visibility of the web script in the Alfresco repository. The following options are available:
  • public: The web script is available to public use.
  • internal: The web script is intended for internal use only.
  • limited_support: The web script is not fully supported. It is not recommended for use in production.
  • sample: The web script is provided as a sample, not intended for use in production.
<cache> The HTTP caching behavior for an endpoint. The following options are available:
  • <never>true</never>: Caching is disabled. Web script responses are not cached by clients or proxies.
  • <never>false</never>: Caching is not explicitly disabled, and web script responses can be cached if allowed by other cache settings.
  • <public>true</public>: Public caching is allowed. Web script responses are cached by public caches.

Web script controller script

A web script controller script is a JavaScript file that contains the actual logic of a web script.

The controller script can query the repository to build a set of data items, known as a model, to render in the response. It might also update the repository for URIs that intend to modify the repository (PUT, POST, and DELETE method bindings). The JavaScript has access to the URI query string, services, and repository data entry points.

// check that search term has been provided
if (args.q == undefined || args.q.length == 0)
{
   status.code = 400;
   status.message = "Search term has not been provided.";
   status.redirect = true;
}
else
{
   // perform search
   var nodes = search.luceneSearch("TEXT:" + args.q);
   model.resultset = nodes;
}        

Web script response template

Known as views, web script response templates render output in the correct format for specific needs, such as HTML, Atom, XML, RSS, JSON, CSV, or any combination of these.

The HTTP response is rendered by using one of the supplied templates, where the chosen template is based on the required response content type or status outcome. The template has access to the URI query string, common repository data entry points, and any data items built by the optional controller script.

<html>
  <body>
    <img src="${url.context}/images/logo/AlfrescoLogo32.png" alt="Alfresco" />
    Blog query: ${args.q}
    <br/>
    <table>
<#list resultset as node>
     <tr>
       <td><img src="${url.context}${node.icon16}"/></td>
       <td><a href="${url.serviceContext}/api/node/content/${node.nodeRef.storeRef.protocol}/${node.nodeRef.storeRef.identifier}/${node.nodeRef.id}/${node.name?url}">${node.name}</a></td>
     </tr>
</#list>
    </table>
  </body>
</html>