Introduction

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:

Examples

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

expand

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"/>.carerix.com/cxportal/job-vacancy/<cx:write value="$pub.publicationID/"/>/>

The proper wayusing valid HTML and the cx:element tag

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

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"/>"
</cx:let>

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"/>
</cx:let>

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 />
</cx:fetch>
</cx:let>

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)">
...
</cx:fetch>
</cx:let></cx:let>

Direct SQL qualifiers

On rare occasions, the only way to get the proper results is to do some calculations on the database side. This is possible using SQL qualifers. Please note that these are database specific and should be used as a last resort only. I.e. when calculations on values or columns are necessary.

Example: Canddiates that have their birthday today (birth year is irrelevant)

<cx:fetch entity="CREmployee" sqlqualifier="to_char(toUser.birthDate, 'DD-MM') = to_char(current_date, 'DD-MM')">
<cx:write value="$item.informalName"/><br />
</cx:fetch>
Job orders with a work location within a certain radius ($d) from postal code $pc.
<cx:let name="clu" value="CXCoordLookup" invoke="namedClass.sharedInstance.coordinates">
<cx:let name="pc4" value="$pc" invoke="substringWithMaxLength:" arg0="4">
<cx:let name="co" condition="$pc4.length > 0" iftrue="$clu" invoke="$pc4">
<cx:let name="dm" value="$d.numberValue" invoke="numberByMultiplyingBy:" arg0="1000">
<cx:let name="sql" condition="($co != nil) and ($dm > 0)" iftrue="
toVacancy.coordX >= ${co.x} - ${dm} AND toVacancy.coordX <= ${co.x} + ${dm} AND
toVacancy.coordY >= ${co.y} - ${dm} AND toVacancy.coordY <= ${co.y} + ${dm} AND
(toVacancy.coordX - ${co.x})^2 + (toVacancy.coordY - ${co.y})^2 <= ${dm}^2" expand="1">
<cx:fetch entity="CRVacancy" sqlqualifier="$sql">
...
</cx:fetch>
</cx:let></cx:let></cx:let></cx:let></cx:let>

Note: Only Dutch postal codes have the required coordinates

Did this answer your question?