This is the tenth and final 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 looked at Strings, regular expressions and other objects. This article will finish this series by looking at Arrays, Functions, and techniques for processing objects.

Arrays

The purpose of an array is to contains numbered values NOT named values.

In Sage CRM the majority of the work we will do, you will be using other objects rather than Arrays.

This is because Objects in JavaScript are ‘expando’ which means an object can be created and new properties can be dynamically created and assigned to it – and because properties are named they are typically easier for users to use. Much of the work with Record objects and QueryObjects, Screens and list that you will be doing is essentially using the expando nature of JavaScript.

But with Array Values are accessed via the [ ] operator

First element of array is 0
arrayTest[0] = 1;
arrayTest[1] = “Hello World”;
arrayTest[2] = arrayA[0] + arrayA[1];

Arrays can hold all data type including other objects.

You can see the way in which we can define an array.

Functions

The type of object with which you will become very familiar is a function.

You can see here I have defined a function which is bundled bit of behaviour for use in checking the case of strings. This will see whether these are correctly capitalised.

This example assumes that it is for use in custom content but it could be used within any server-side code.

It makes use of the methods and properties of string objects.

Handling Objects: while, do while and for loops

Consider the code below

This is a “while” loop

The while loop loops through a block of code as long as a specified condition is true.

This in comparison with the ‘while’ loop is the ‘do while’

In a “do while” loop the contents of the loop is always done at least once. This example works because a company is always created with a person.

This is a “for” loop.

This is useful where we need to cycle through all of the properties of an object looking for a particular value.

And lastly a Collection is a specific type of object with JavaScript this define to hold sets of related data. Within Scripting of an ASP, we run into these types of objects when handling inbound data that can be submitted as part of an HTTP request. This is either in the form that is posted to the server or in this case, where we can examine the variables contained in the URL that was sent to the server – this is looking at the querystring, the set of variables and their values.

I hope you have found these articles of interest.

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.