Objectif Lune joins Upland Software.Learn more >

Back to all How-tos

Basic Scripted Condition in Workflow

While there are some very powerful, and simple to use, conditions available in the Process Logic tasks of Workflow, it’s undeniable that sometimes you might need a bit more… umph to get the job done.

The following demonstrates the very basics of creating a scripted condition in Workflow. To start off, drag the Run Script task from either the Actions or Process logic category into your process, and in the Insert As menu that appears select Condition.

Basic Condition

Let’s start with the very basics. Here’s the JavaScript version:

var check_me = Watch.GetVariable("TrueFalseValue");
if(check_me == "true") {
    Script.ReturnValue = 1;
} else {
    Script.ReturnValue = 0;
}

And the VBScript version:

Dim check_me
check_me = Watch.GetVariable("TrueFalseValue")
if (everythingOK = "true") then
 Script.ReturnValue = 1
else
 Script.ReturnValue = 0
end if

Obviously this means that Script.ReturnValue = 1 will cause the condition to return true, and execute the right part of the process, and vice versa.

Condition based on database results

Combining this condition with a database query, we can get some pretty powerful actions going on. Here’s a condition that checks whether a query returns a result or not (for instance checking if a user exists by attempting to retrieve their information in the database):

// Get DB location
var dbloc = "c:/data/database/users.mdb";

var conn = new ActiveXObject("ADODB.Connection");
var rs = new ActiveXObject("ADODB.Recordset");
var src = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + dbloc + ";";

var query = "SELECT Last_Name FROM Table1 WHERE Email = '" + Watch.GetVariable("request_email") + "'";

conn.Open(src);
rs.Open(query,conn,1,1);
Watch.Log("Number of records retrieved: " + rs.RecordCount + " Number of fields retrieved per record: " + rs.Fields.Count, 2);
if(rs.Fields.Count > 0) {
    Script.ReturnValue = 1;
} else {
    Script.ReturnValue = 0;
}

The above example is in JavaScript only

Leave a Reply

Your email address will not be published. Required fields are marked *