Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing cfif in coldfusion
    primarykey
    data
    text
    <p>For example, please consider the following code snippet:</p> <p><strong>Scenario 1:</strong></p> <p>The company name I received as a part of SOAP response is as follows:</p> <pre><code>&lt;Company&gt;Amazon, Inc &lt;/Company&gt; </code></pre> <p><strong>Scenario 2:</strong></p> <p>Another company name I received as a part of SOAP response is as follows:</p> <pre><code>&lt;Company&gt;Google, Inc &lt;/Company&gt; </code></pre> <p>Basically, from the user end I am inputting some information and based on that I am getting different company names inside the <code>&lt;Company&gt;</code> tag.</p> <p>The following code shows how I am storing the response in XMLResponse variable</p> <pre><code> &lt;cfset XMLResponse = XmlParse( httpResponse.fileContent.Trim() ) /&gt; </code></pre> <p>The following piece of code shows how I am parsing the response and storing the content in a variable:</p> <pre><code>&lt;cfset arrCOMPANY = XmlSearch( XMLResponse, "//*[name()='Company']" ) /&gt; </code></pre> <p>So now I have arrCOMPANY = Amazon, Inc is I happen to be in Scenario and Google, Inc otherwise.</p> <p><strong>My Question:</strong></p> <p>I have to insert these data into the database based on the company name and set an integer field to be equal to 1 if the company name is Amazon,Inc and set it to zero otherwise for all other companies.</p> <p>Please let me know if I am following the right path:</p> <p>I am thinking of writing two cfqueries based on the company names and hence I am thinking to place the following condition :</p> <pre><code>&lt;cfif arrCompany eq "Amazon, Inc"&gt; // Here I will write cfquery with an integer field = 1 Or &lt;cfif arrCompany eq "Google, Inc"&gt; // Here I will write cfquery with integer field 0 </code></pre> <p>So, am I doing the right comparision, I am wondering whether the company names that I am comparing with eq sign will be actually compared or not as it contains spaces after first word ( say for example the space between Amazon, and Inc).</p> <p>Please share your experience.</p> <p>Thanks</p> <p>Here is what I did:</p> <p>I have applied trim function on specific element as well. For example:</p> <p>The Value in the CompanyName variable is <code>Amazon, Inc</code></p> <pre><code>&lt;cfset CompanyName = Trim(arrCompany[1])&gt; // adding index 1 because it's a complex structure </code></pre> <p>Here is how I am trying to use cfif condition:</p> <pre><code>&lt;cfif CompanyName eq "Amazon, Inc"&gt; &lt;cfset m = 1&gt; &lt;cfelse&gt; &lt;cfset m = 0&gt; &lt;/cfif&gt; &lt;cfoutput&gt;#m#&lt;/cfoutput&gt; </code></pre> <p>Despite doing above, I am getting <code>0</code> as my output. Please let me know if I am comparing wrong.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload