CxScript Elements - cx:write
Updated over a week ago

With cx:write, the most used element in CxScript, you write the value of a constant or variable into the document at the current position, like:

<cx:write value="$activity.toEmployee.lastName"/>

The value attribute is obligatory and used to determine what actually is to be written. Determine the way the value is written by the use of one or more other attributes.


The following table contains the attributes available with the cx:write element. Obligatory attributes are bold.


The attribute content determines how the content (the part enclosed by the opening and closings tags) should be written.

The following options are available:

  • prepend (the default behaviour): the content is written before the value of the value attribute; however, if the value attribute is empty (nil) than the content is suppressed and nothin is written;

  • append: the content is written after the value of the value attribute; however, if the value attribute is empty (nil) than the content is suppressed and nothin is written;

  • default: the content is only written when the value of the value attribute is empty (nil).


<cx:write value="$" content="default">Unknown</cx:write>

phone=nil -> "Unknown"

phone="123" -> "123"

<cx:write value="$" content="append"> is the number</cx:write>

phone=nil -> ""

phone="123" -> "123 is the number"

<cx:write value="$" content="prepend">Tel. </cx:write>

phone=nil -> ""

phone="123" -> "Tel. 123"


Use this attribute to, for instance, insert a photo into the document. For this you would first create a template like "photo.bin" with only the following content:

<cx:write data="$"/>

Use such a template within another template as follows:

<img src="<cx:hyperlink action='view' string='1' template='photo.bin'>

  <cx:parameter name='eid' value='$employee.employeeID'/>


With the data attribute you could also create a link to, for instance, a MS-Word document with the resume of a candidate.
Again, first create a template that will contain the actual resume, like:

<cx:let name="document" value="$form.aid.@fetchByID.CRAttachment.@first">

  <cx:if condition="document.content.md5Hash.description = form.chk.@first.description">

  <cx:write data="$document.content"/>



Link the resume from another template like ($employee references a candidate):

<cx:foreach list="$employee.attachments" filter="toTypeNode.value like 'cv'" count="1">

  <cx:hyperlink action="view" target="_blank" template="cv.bin">

    <cx:parameter name="aid" value="$item.attachmentID"/>

    <cx:parameter name="chk" value="$item.content.md5Hash"/>

    Bekijk CV



Note that the resume construction contains a checksum key 'chk' (a so called MD5Hash checksum) for security reasons. It also adds a key 'aid' to the link (cx:hyperlink). This key tells the system that the user has the right to obtain the checksum. 


Format a date value with the attribute dateFormat through the following symbols:

The following example shows how parts of a date are being specified in a dateFormat:

<cx:write value="$utilities.currentDate" dateformat="Today it is %a, %e %B %Y." language="English"/>

This results in the following date: Today it is Monday, 14 february 2005.


The HTML layout stays preserved when you use the attribute html in HTML templates as follows: html="$YES". The use of the attribute html is to indicate that the value is an HTML fragment. If this attribute is not used the HTML codes are not interpreted but printed literally.


The result of the dateformat and numberformat attributes can be language dependent, like the names of days and months. Therefor always use the language attribute in combination with the use of any of these 2 attributes. For the Dutch language the correct value for the language attribute is: "Dutch". Other valid values are: "English" and "German".


Format a number value with the numberFormat attribute through the following symbols:

Thus, suppose a variable n contains the number 4217,5, you could present this number like:

<cx:write value="$s" numberformat="00000"/>

<cx:write value="$s" numberformat="#,##0.00" language="Dutch"/>

This results respectively in the following output: "04217" and "4.217,50". Notice that specifying the Dutch language translates the the decimal point into a decimal comma. 


To specify the number of to be written characters use the width attribute; if nescessary spaces are added to the right of the text. This way a fixed column width is obtained when using a fixed width font like Courier.


See cx:let for an explanation of this attribute.

Keywords: UD-2568

Did this answer your question?