Link to home
Start Free TrialLog in
Avatar of lonnyo
lonnyo

asked on

Multiple OR Conditions in CFIF

I have this loop that loops through a series of attributes.  For some reason they have setup an attribute for each month that has a value of true or false.  I want to skip over these so they are not added to the query I am creating (using QueryNew - data comes from a soap call).

The code that I have is not working plus I am sure there is a better way.

Here is the code I have to prevent the code from creating a row:
<cfif includeAttribute>
        	<cfif AttributeNode["DisplayName"].xmlText NEQ "January" OR 
				  AttributeNode["DisplayName"].xmlText NEQ "February" OR 
				  AttributeNode["DisplayName"].xmlText NEQ "March" OR 
				  AttributeNode["DisplayName"].xmlText NEQ "April" OR 
				  AttributeNode["DisplayName"].xmlText NEQ "May" OR 
				  AttributeNode["DisplayName"].xmlText NEQ "June" OR 
				  AttributeNode["DisplayName"].xmlText NEQ "July" OR 
				  AttributeNode["DisplayName"].xmlText NEQ "August" OR 
				  AttributeNode["DisplayName"].xmlText NEQ "September" OR 
				  AttributeNode["DisplayName"].xmlText NEQ "October" OR 
				  AttributeNode["DisplayName"].xmlText NEQ "November" OR 
				  AttributeNode["DisplayName"].xmlText NEQ "December">					
			<cfset row = queryAddRow(getAttributes, 1)>
			<cfset getAttributes.VenueID[row] = CurrentVenueID>
			<cfset getAttributes.DisplayName[row] = AttributeNode["DisplayName"].xmlText>
			<cfset getAttributes.Type[row] = AttributeNode["Type"].xmlText>
			<cfset getAttributes.Value[row] = AttributeNode["Value"].xmlText>
            </cfif>
		</cfif>

Open in new window

Avatar of _agx_
_agx_
Flag of United States of America image

I would create a list of keys to exclude before all loops. Then use list functions to determine if you should still add the attribute. The rest of the code is the same.

Watch out for line wrapping

<cfset excludeAttributes = "January,February,March,April,May,June,July,August,September,October,November,December"> 
...   
<!--- if it's a month, set includeAttribute = false --->
<cfif includeAttribute> 
    <cfset attributeName = TRIM(AttributeNode["DisplayName"].xmlText)>
     <cfset includeAttribute = listFindNoCase(excludeAttributes , attributeName)>
</cfif>

<!--- add the row same as before --->
<cfif includeAttribute>
     <cfset row = queryAddRow(getAttributes, 1)>
     <cfset getAttributes.VenueID[row] = CurrentVenueID>
     <cfset getAttributes.DisplayName[row] = AttributeNode["DisplayName"].xmlText>
     <cfset getAttributes.Type[row] = AttributeNode["Type"].xmlText>
     <cfset getAttributes.Value[row] = AttributeNode["Value"].xmlText>
</cfif>
....

Open in new window


As an aside didn't the original code have some of the values (like AttributeNode["DisplayName"].xmlText) stored in variables already?
Avatar of lonnyo
lonnyo

ASKER

I need to take a closer look at this.  May not be until later tonight or tomorrow.

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lonnyo

ASKER

That worked with the correction above.  Thank you very much.