This is the eighth 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 discussed arithmetic and assignment operators. In this article, I will use those ideas and develop the idea of conditional behaviour and compound statements.

Consider this very simple statement

This introduces to us the idea of conditional behaviour. Here I am checking the value of an object’s property ‘CRM.Mode’ against the value contained in a variable ‘View’.

What I want to think about now is the comparison operator that has been used here.

This is the == (equals, equals) sign. This is a test for equality.

We can change this so that we can test for inequality.

In this example, I am now checking the CRM.Mode does not equal the value of a variable ‘Edit’.

And there are other logical operators that we can use, greater than or equal, Less than or equal and exactly equal (that’s the same value and same data type).

Below is an example workflow condition.

This is a server-side example. This is exactly the sort thing that you will find in the workflow components available to download from the developer examples

You can see that I have used a method GetContextInfo to grab the value of the current ID of the opportunity in content. I then put that in a variable ‘intRecordId’ which I have then used to retrieve all the quotes for that opportunity. I then used an implicit Boolean test to see if the property of the record object that has been returned actually contains any rows – the eof property stands for ‘end of file’ – if that is true then there are no records in the data set.

I didn’t have to use "else“ but I want to set deliberately the alternative value for ‘Valid’. Valid is a system variable used to control workflow – we will meet that later on again.

And if I have to want further checks I could have added Nesting of statements.

In my next article, I will have another look at Strings, regular expressions and other objects.