Alfresco JavaScript Console

What is one of the first packages you install on a new Alfresco with Share instance? I think that for many Alfresco developers it will be Alfresco JavaScript Console made by Florian Maul and Jens Goldhammer from fme AG. Simple, but very powerfull tool that allows you to run a javascript code on a server side. I’m using it almost everyday to fix various kinds of users’ issues. I like it, because I can do almost everything without restarting server.

In JavaScript Console you may also fill out a Freemeaker template, set user authority as well as set the webscript URL arguments (root object args), so it is also a superb tool for creating and testing new JavaScript WebScripts. But there is a lack of settings if you need to write a POST webscript, so I decided to add several new functionalities to JS Console.

A new card with request parameter settings
A new card with request parameters settings

I added a new card where you can easily manipulate request parameters. For example you may choose a type of the request. Depends on which setting you select you get access to specific additional options like request content or request fields which can be useful to simulate JSON/form-data POST webscripts.

New supported root objects:

  • json,
  • formdata,
  • headers,
  • headersM,
  • argsM.


When you make an API, you often need a webscipt that accept JSON as a request content. If the content type of the POST is application/json then the Web Script Framework parses the JSON into the helper object called json. This allows the developer to access the JSON data using properties with the get/has method.

Simulate JSON POST in JS Console
Simulate JSON POST in JS Console

There are two kind of object you can get. If the data posted is a JSON object, the json root object will be of type JSONObject. In case of a JSON array the json root object will be of type JSONArray.


Get a data from JSON request

JavaScript input (like

model.result = json.has("name") ? 
                 "Hello "+json.get("name")+"!" : 
                 "I don't know your name :(";

Freemarker input (like


Request type: JSON (POST)

Request content (JSON):

   "name": "John"

Freemarker HTML output:

Hello John!

Log a JSON Array request

JavaScript input:


Request type: JSON (POST)

Request content (JSON array):

["test1", "test2"]

Console output:

DEBUG - test1
DEBUG - test2


When multipart/form-data is posted to a web script, the Web Script Framework provides a special root object named formdata that allows access to the posted request through a simple API, hiding the complexities of parsing the request directly. The API provides access to each form field, including its name and value. For form fields of type file, the content of the uploaded file is also provided. Besides that, all fields other than those of type file are added to the root objects args and argsM.

Simulate a form-data POST request
Simulate a form-data POST request


JavaScript input:




var upload = companyhome.createFile("upload" + companyhome.children.length + "_" + formdata.fields[1].filename) ;[1].content); = "UTF-8"; = formdata.fields[1].filename;;

Request type: Form-data (POST)

Request fields:


Console output:

DEBUG - [Lorg.springframework.extensions.webscripts.servlet.FormData$FormField;@204110a3
DEBUG - true
DEBUG - test1
DEBUG - false
DEBUG - dummy
DEBUG - test2
DEBUG - true
DEBUG - 0900021337.pdf
DEBUG - application/pdf
DEBUG - 0900021337.pdf

headers and headersM

headers is an associative array that contains a map of request header values indexed by header name.

headersM is similar map but it has multi-valued request headers, where each key is also a header name, but each value is an array containing all respective header values, even if only one is supplied.

Additional request headers' parameters
Additional request headers’ parameters


JavaScript input:


Additional request headers:

If-Modified-SinceWed, 21 Oct 2015 07:28:00 GMT

Console output:

DEBUG - 1445412480000
DEBUG - en


You can download JS Console with new features from my github.

I hope you enjoy new features. If you find a bug in new functionality send me e-mail at

Be the first to comment

Leave a Reply

Your email address will not be published.