CxScript, tips and tricks
Updated over a week ago


Our objective is that this page will contain CxScript snippets, howto's, hownotto's, to assist in creating CxScript templates.

Please note
That creating templates can be complicated. Carerix is not responsible for templates created or modified by the customer. The Carerix Helpdesk is not able to debug your templates for you.
There is always the option to have Carerix create the templates for you.

Note :
This page is under construction. Please refer to the Dutch Pages [1] for now.

Qualifiers: only attributes are allowed

When working in CxScript, you should make the distinction between attributes and methods:

attributesare real properties, these are stored in the databaseExample: employee.birthDatemethodsare "other things" you can ask, as defined by business logic.Example: employee.age (this is not stored in the database, but calculated "on demand")

Since qualifiers are handled directly by the database, only attributes are allowed in qualifiers.

Predifined variables

The following variablas are available in all templates:

These variables are available in document templates:

Some global objects can be reached in a roundabout way:


Name of customer: <cx:write value="$utilities.userDefaults.Customer"/>
Browser used: <cx:write value="$request.headers" invoke="user-agent.@first"/>


Sometimes you need to combine values into another value. To do so, you can use "expand", like this:
Suppose m1="Jan", m2="Feb", m3="Mar"

<cx:let name="q" value="${m1}, ${m2}, ${m3}" expand="1">

will set q to "Jan, Feb, Mar" The values of the m1, m2 and m3 are expanded before use.

building a URL

The quick and dirty wayworks, but is not valid HTML before expansion (code within code):

<a href="http://<cx:write value="$utilities.userDefaults.Customer"/><cx:write value="$pub.publicationID/"/>/>

The proper wayusing valid HTML and the cx:element tag

<cx:let name="pubURL" value="http://${utilities.userDefaults.Customer}${pub.publicationID}/" expand=1>
  <cx:element tag="a">
    <cx:parameter name="href" value="$pubURL"/>
    <cx:parameter name="target" value="_blank"/>

The same way you can build any other HTML tag you need, e.g. <cx:element tag="td">…</cx:tag>

empty replacement

Suppose you want to suppress the "bar" using:

**WRONG, returns "foo arg1 baz"**
<cx:let name="newString" value="foo bar baz" invoke="replace:by:" arg0="bar" arg1="">
"<cx:write value="$newString"/>"

This will return FOO arg1 baz. Instead, use:

**RIGHT, returns "foo baz"**
<cx:let name="newString" value="foo bar baz" invoke="replace:by:" arg0="bar" arg1="$nil">
<cx:write value="$newString"/>

The $nil will expand into the empty string required.

Candidates without e-mail address, creating a qualifier on the fly

<cx:let name="q" value="emailAddress != nil" invoke="qualifierValue">
<cx:fetch entity="CREmployee" qualifier="not (toUser.emailAddresses matchesQualifier: $q)">
<cx:write value="$item.informalName"/><br />

Gotcha: relations in qualifiers

ProblemFind candidates with skill X and skill Y.Wrongthe following will not give a result:<cx:fetch entity="CREmployee" qualifier="(skills.toSkillLevel2.value = X AND skills.toSkillLevel2.value = Y)">explanation: For every relation one' join is created, no matter how many times it is used in a query. So, key-paths with a specific "to-many" relationship (like skills) will always refer to the same object. The above query will therefore look for a skill that is both X and Y.

This coupling can be circumvented in two ways:Right: Use a relationship with an alternative nameWorks only when this alternative relationship is defined within Carerix:(skills.toSkillLevel2.value = X AND otherSkills.toSkillLevel2.value = Y)Right: Use a sub query

<cx:let name="q1" value="toSkillLevel2.value = X" invoke="qualifierValue">
<cx:let name="q2" value="toSkillLevel2.value = Y" invoke="qualifierValue">
<cx:fetch entity="CREmployee" qualifier="(skills matchesQualifier: $q1) AND (skills matchesQualifier: $q2)">

Note: Only Dutch postal codes have the required coordinates.

Keywords : UD-1207

Did this answer your question?