This is the ninth article in a series provided for non-technical System Administrators who wish to understand more about using JavaScript to control workflow and to implement simple customizations using the language.

My last article developed the idea of conditional behaviour and compound statements. In this article, I will have another look at Strings, regular expressions and other objects.

A String is a sequence of letters and numbers. And this supports the use of Unicode.

Strings are indicated by using 'quotation characters'

“Double Quotes”
‘And Single Quotes’

You can nesting quotes in strings. Below is a typical example being defined. This is a 'where clause' that would be passed to the database from within a script in Sage CRM.

strArg = “comp_type=‘Competitor’”;

Note: The order of the nesting of the strings is important because SQL allows strings only to be in single quotes.

If you want to use a quote a literal character within a string then you would need to 'escape' it from its original meaning in JavaScript.

Consider the examples below

Escapes (use \ in a string to change the meaning of character)

\’ = Apostrophe doesn’t end string e.g. O’clock
\”= Double quote doesn’t end string
\\= Allows single backslash character in pathnames etc.

Concatenation
+ symbol add strings together

Regular Expressions

Very often within Sage CRM may have to search for patterns of characters within a string. JavaScript provides a mechanism called Regular Expressions to do that.

A regular expression is an object that describes a pattern of characters.

Regular expressions are used to perform pattern-matching and "search-and-replace" functions on text.

Below is a script example that could be used in a Case Summary screen within Sage CRM.

A variable strDescription has been created. This is the value of the case description field. I have used the client side API here to read the value.

I then created a Create regular expression object using the first syntax

I then found a match within the string, which is returned and if there is a result (so the result is not null and is implicitly true) then I can write a message on the screen using the API.

My next article will finish this series by looking at Arrays, Functions, and techniques for processing objects.

An Introduction to JavaScript in Sage CRM

The links to the other articles in the series are listed below

  1. An Introduction to JavaScript in Sage CRM.
  2. The relationship that JavaScript has with other languages and where scripting can be used in practice.
  3. The syntax of the language and the different objects available.
  4. The different types of JavaScript data types and how we use them in Sage CRM scripts.
  5. The objects that are available within the Browser.
  6. Binding a script to an event.
  7. Statements in JavaScript.
  8. Conditional behaviour and compound statements.
  9. Another look at Strings, regular expressions and other objects.
  10. Arrays, Functions, and techniques for processing objects.