Latest News

the latest news from our team

Conditionally Setting a Variable Based on Another Variable

Use conditional logic in eFORMz to set a variable based on the value of another variable. Setting up this example includes the following steps:

  1. Define the variables
  2. Create procedures
  3. Define a condition on each procedure

This example comes from a Minisoft customer and includes the following variables:

  • EmailLookup: A single email address returned from a database query
  • EmailArchive: A static email address preceded by a semicolon
  • EmailSentTo: The variable use in the To field of the email form

In this example, eFORMz emails invoices to customers who have an email address in the database. Not all customers have an email address in the database, which results in a null value from the SQL query. However, every invoice is emailed to an internal email address for archiving. The variable EmailArchive is concatenated with EmailLookup if the database query returns an email address. The values look like this:

  • EmailLookup: receiving@yourshoeco.com
  • EmailArchive: ;archive@minisoft.com
  • EmailSentTo:  receiving@yourshoeco.com;archive@minisoft.com

An empty EmailLookup results in the following values:

  • EmailLookup:
  • EmailArchive: ;archive@minisoft.com
  • EmailSentTo:  ;archive@minisoft.com

This approach works only for email servers that ignore initial semicolons. If your email server rejects an initial semicolon, you can make the semicolon a separate variable, and conditionally concatenate it when EmailLookup is not null, as shown below. This condition must be set in a procedure; you cannot put a condition on a variable.

Define the variables

Create the following variables:

emailA

  • EmailLookup uses a database connection to select an email address as shown below. The parameter passed is the customer ID, which is read from the data file.
    select EmailAddress from emaildb where AccountNumber = ?
  • Semicolon and EmailArchive use constant values.
  • EmailSendTo is empty for now.

Create procedures

Conditional concatenation is available only through a Set Variable procedure. You can use a concatenate function on variables, but cannot put conditions on variables or functions. Two procedures are created to set EmailSendTo based whether EmailLookup is null or not null.

  1. Right click the form > Add Pre-condition procedure > Set variable.
  2. Name the procedure SetEmailConcatenationNOTNULL, select variable EmailLookup, and click OK.
  3. Select EmailSendTo and click OK.
  4. Right click Actions > Add Function > Concatenate, click Variable, select Semicolon, and click OK.
  5. Right click Actions > Add Function > Concatenate, click Variable, select EmailArchive, and click OK.
  6. Create another procedure named SetEmailConcatenationNULL and complete the same steps, except do not concatenate any variables.

Set conditions on the procedures

Finally, add conditions when these procedures are used.

  1. Right click the procedure name, SetEmailConcatenationNOTNULL > Add AND Condition > Is not equal to.
  2. Next to of variable, select the variable EmailLookup. Click constant, and check that the text area has no value, including no space.
  3. Click OK. When EmailLookup contains any value from the database, that value is concatenated to the archive email address.
  4. Create a condition the same way on the procedure SetEmailConcatenationNULL, except select Is equal to. When no value is returned from the database, nothing is concatenated, and the email is sent only to the archive email address. Here are the procedures with their conditions:

Leave a Reply

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

*

code