Multiple OR Conditions in CFIF

lonnyo
lonnyo used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2015

Commented:
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?

Author

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

Thank you.
Most Valuable Expert 2015
Commented:
Actually small typo correction. This line:
 
     <cfset includeAttribute = listFindNoCase(excludeAttributes , attributeName)>

Should be:

     <cfset includeAttribute = NOT listFindNoCase(excludeAttributes , attributeName)>

Author

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial