{"id":3944,"date":"2017-03-24T20:29:44","date_gmt":"2017-03-24T20:29:44","guid":{"rendered":"https:\/\/alt2.minisoft.com\/support\/?p=3944"},"modified":"2017-03-24T20:29:44","modified_gmt":"2017-03-24T20:29:44","slug":"conditionally-setting-a-variable-based-on-another-variable","status":"publish","type":"post","link":"https:\/\/c002.minisoft.com\/support\/conditionally-setting-a-variable-based-on-another-variable\/","title":{"rendered":"Conditionally Setting a Variable Based on Another Variable"},"content":{"rendered":"<p>Use conditional logic in eFORMz to set a variable based on the value of another variable. Setting up this example includes the following steps:<\/p>\n<ol>\n<li>Define the variables<\/li>\n<li>Create procedures<\/li>\n<li>Define a condition on each procedure<\/li>\n<\/ol>\n<p>This example comes from a Minisoft customer and includes the following variables:<\/p>\n<ul>\n<li>EmailLookup:\u00a0A single email address returned from a database query<\/li>\n<li>EmailArchive:\u00a0A static email address preceded by a semicolon<\/li>\n<li>EmailSentTo:\u00a0The variable use in the To field of the email form<\/li>\n<\/ul>\n<p>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:<\/p>\n<ul>\n<li>EmailLookup:\u00a0receiving@yourshoeco.com<\/li>\n<li>EmailArchive:\u00a0;archive@minisoft.com<\/li>\n<li>EmailSentTo: \u00a0receiving@yourshoeco.com;archive@minisoft.com<\/li>\n<\/ul>\n<p>An empty EmailLookup results in\u00a0the following values:<\/p>\n<ul>\n<li>EmailLookup:<\/li>\n<li>EmailArchive:\u00a0;archive@minisoft.com<\/li>\n<li>EmailSentTo: \u00a0;archive@minisoft.com<\/li>\n<\/ul>\n<p>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.<\/p>\n<p><strong>Define the\u00a0variables<\/strong><\/p>\n<p>Create the following variables:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-3950 aligncenter\" src=\"https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2016\/02\/emailA-300x116.jpg\" alt=\"emailA\" width=\"300\" height=\"116\" srcset=\"https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2016\/02\/emailA-300x116.jpg 300w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2016\/02\/emailA-150x58.jpg 150w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2016\/02\/emailA-250x97.jpg 250w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2016\/02\/emailA.jpg 305w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<ul>\n<li>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.\n<pre>select EmailAddress from emaildb where AccountNumber = ?<\/pre>\n<\/li>\n<li>Semicolon and EmailArchive use constant values.<\/li>\n<li>EmailSendTo is empty for now.<\/li>\n<\/ul>\n<p><strong>Create procedures<\/strong><\/p>\n<p>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.<\/p>\n<ol>\n<li>Right click the form &gt; Add Pre-condition procedure &gt; Set variable.<\/li>\n<li>Name the procedure SetEmailConcatenationNOTNULL, select variable EmailLookup, and click OK.<img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-4798 aligncenter\" src=\"https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email1-300x172.jpg\" alt=\"\" width=\"300\" height=\"172\" srcset=\"https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email1-300x172.jpg 300w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email1-150x86.jpg 150w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email1-250x144.jpg 250w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email1-314x180.jpg 314w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email1.jpg 371w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/li>\n<li>Select EmailSendTo and click OK.<\/li>\n<li>Right click Actions &gt; Add Function &gt; Concatenate, click Variable, select Semicolon, and click OK.<\/li>\n<li>Right click Actions &gt; Add Function &gt; Concatenate, click Variable, select EmailArchive, and click OK.<img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-4799 aligncenter\" src=\"https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email2.jpg\" alt=\"\" width=\"282\" height=\"81\" srcset=\"https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email2.jpg 282w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email2-150x43.jpg 150w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email2-250x72.jpg 250w\" sizes=\"(max-width: 282px) 100vw, 282px\" \/><\/li>\n<li>Create another procedure named SetEmailConcatenationNULL and complete the same steps, except <strong>do not<\/strong> concatenate any variables.<img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-4801 aligncenter\" src=\"https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email3.jpg\" alt=\"\" width=\"292\" height=\"143\" srcset=\"https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email3.jpg 292w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email3-150x73.jpg 150w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email3-250x122.jpg 250w\" sizes=\"(max-width: 292px) 100vw, 292px\" \/><\/li>\n<\/ol>\n<p><strong>Set conditions on the procedures<\/strong><\/p>\n<p>Finally, add conditions when these procedures are used.<\/p>\n<ol>\n<li>Right click the procedure name, SetEmailConcatenationNOTNULL &gt; Add AND Condition &gt; Is not equal to.<\/li>\n<li>Next to of variable, select the variable EmailLookup. Click constant, and check that the text area has no value, including no space.<\/li>\n<li>Click OK. When EmailLookup contains any value from the database, that value is concatenated to the archive email address.<\/li>\n<li>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:<img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-4802 aligncenter\" src=\"https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email4-300x232.jpg\" alt=\"\" width=\"300\" height=\"232\" srcset=\"https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email4-300x232.jpg 300w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email4-150x116.jpg 150w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email4-250x193.jpg 250w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email4-233x180.jpg 233w, https:\/\/c002.minisoft.com\/support\/wp-content\/uploads\/2017\/03\/email4.jpg 312w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Use conditional logic in eFORMz to set a variable based on the value of another variable. Setting up this example includes the following steps: Define the variables Create procedures Define a condition on each procedure This example comes from a Minisoft customer and includes the following variables: EmailLookup:\u00a0A single email address returned from a database [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66,115],"tags":[178,128],"_links":{"self":[{"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/posts\/3944"}],"collection":[{"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/comments?post=3944"}],"version-history":[{"count":16,"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/posts\/3944\/revisions"}],"predecessor-version":[{"id":4803,"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/posts\/3944\/revisions\/4803"}],"wp:attachment":[{"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/media?parent=3944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/categories?post=3944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/tags?post=3944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}