What I am trying to do is if pcount is = 0
<cfif (isDefined("session.checkout.quantity.pcount")) eq 0>
then loop this but skip the last loop
<cfif BAdd NEQ session.checkout.quantity.bcount>
<cfinclude template="../../../ddl/bandor.cfm">
and if pcount is not equal to 0
(zero is the number 0 in a drop down menu not just blank)
<cfif (isDefined("session.checkout.quantity.pcount")) neq 0>
then loop this everytime
<cfinclude template="../../../ddl/bandor.cfm">
This is the full code if anyone can please tell me what I am doing wrong?
<cfif (isDefined("session.checkout.quantity.pcount")) eq 0>
<cfif BAdd NEQ session.checkout.quantity.bcount>
<cfinclude template="../../../ddl/bandor.cfm">
</cfif>
</cfif>
<cfif (isDefined("session.checkout.quantity.pcount")) neq 0>
<cfinclude template="../../../ddl/bandor.cfm">
</cfif>
This is a formatted comment to help you understand what went wrong with your code. This,
<cfif (isDefined("session.checkout.quantity.pcount")) eq 0>
does not check the value of pcount. It actually means,
if variable session.checkout.quantity.pcount does not exist
That's because function isDefined returns a boolean, true or false. However, the way ColdFusion works, the number 0, as well as the strings, "false", "no", and "0" are interpeted as false.
<cfif structKeyExists(session.checkout.quantity, "pcount") AND session.checkout.quantity.pcount eq 0>
<cfif BAdd NEQ session.checkout.quantity.bcount>
<cfinclude template="../../../ddl/bandor.cfm">
</cfif>
<cfelse>
<cfinclude template="../../../ddl/bandor.cfm">
</cfif>
Related
I am following upn on a tute on datatables and found a code which basically iterates over the columns for a order clause but in the case, i do not have a list of order columns hardcoded, its a dynamic list
how can I change this
<cfif form["order[0][column]"] gt 0>
ORDER BY
<cfif form["order[0][column]"] eq '1'>
empname <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
<cfif form["order[0][column]"] eq '2'>
empno <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
<cfif form["order[0][column]"] eq '3'>
ic <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
</cfif>
to be dynamic as my list variable is a comma separated as id,name,email and lots more
The direction I always would go will be to create a Coldfusion array or structure with this fieldNames, like the following.
<cfset orderColumnReference = ['empname', 'empno', 'ic', 'id', 'name', 'email', ...]>
<cfif form["order[0][column]"] GTE ArrayLen(orderColumnReference)>
<cfset orderByColumn = orderColumnReference[form["order[0][column]"]]>
ORDER BY
#orderByColumn# <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
I am trying to add AND ActiveFlag = 'Y' (value in same table as CommitteeRoleCode), but all my attempts either brake it or are ignored. Would anyone be kind enough to assist?
Thanks for your time!
<cfparam name="attributes.Address" default="">
<cfparam name="attributes.CommitteeID" default="0">
<cfparam name="attributes.AddressListName" default="">
<cfif Len(Trim(attributes.CommitteeID)) EQ 0>
<cfset attributes.CommitteeID = 0>
</cfif>
<cfif Len(Trim(attributes.Address))>
<cfset result = "">
<cfloop list="#attributes.Address#" index="i">
<cfif Refind("\[{1}.+\]{1}", i)>
<!---looking for the 'ALL' member type to grab all categories--->
<cfif i EQ "[ALL]">
<cfset l_where = "a.CommitteeRoleCode IS NOT NULL AND c.EmailAddress IS NOT NULL">
<cfelse>
<cfset l_where = "a.CommitteeRoleCode=#Chr(39)##ReReplace(i, "\[|\]", "", "ALL")##Chr(39)# AND c.EmailAddress IS NOT NULL">
</cfif>
<cfquery datasource="#application.datasource#" name="MemberTypeEmails">
Select c.EmailAddress
from (Committee_Role_Ref as a Inner Join Committee_Member as b on a.CommitteeRoleCode=b.CommitteeRoleCode)
Inner Join Contact as c on b.ContactID=c.ContactID
Where #ReReplace(l_where, "\'\'", "'", "ALL")#
AND b.CommitteeID=#attributes.CommitteeID#
</cfquery>
<cfloop query="MemberTypeEmails">
<cfif ReFind("[^#chr(13)##chr(10)##chr(9)##chr(32)#]#{1}.+\..+", EmailAddress)>
<cfif Len(Trim(result))>
<cfset result = result & "," & EmailAddress>
<cfelse>
<cfset result = EmailAddress>
</cfif>
</cfif>
</cfloop>
<cfelseif ReFind(".+#{1}.+\..+", i)>
<cfif Len(Trim(result))>
<cfset result = result & "," & i>
<cfelse>
<cfset result = i>
</cfif>
</cfif>
</cfloop>
<cfset "caller.#attributes.AddressListName#" = result>
</cfif>
You say you are trying to add AND ActiveFlag = 'Y' (value in same table as CommitteeRoleCode). However, the value CommitteeRoleCode appears in two tables and I know this because of this part of the query
a.CommitteeRoleCode = b.CommitteeRoleCode
My suggestion would be to find out which table the ActiveFlag is really in and then prefix it accordingly in the query with either the a. or b. ie
AND a.ActiveFlag = 'Y'
or
AND b.ActiveFlag = 'Y'
Then place your AND clause where indicated below. But if you want more help you should also post what error message you are receiving.
<cfquery datasource="#application.datasource#" name="MemberTypeEmails">
Select c.EmailAddress
from (Committee_Role_Ref as a Inner Join Committee_Member as b on a.CommitteeRoleCode=b.CommitteeRoleCode)
Inner Join Contact as c on b.ContactID=c.ContactID
Where #ReReplace(l_where, "\'\'", "'", "ALL")#
AND b.CommitteeID=#attributes.CommitteeID#
-- AND a. or b. ActiveFlag goes here
AND a.ActiveFlag = 'Y'
</cfquery>
I have problem for getting and working on a structure containing dynamic variable names. I have a structure cfStruct which contains another structure EMAILS. In the last structure the maximum of items is 4
Here my structure for EMAILS
EMAILS":{"1":"mail1#test.com","2":"mail2#test.net","3":"mail3#test.fr"}
I try to create one variable for each item of this structure if it exists by doing that. Nevertheless it doesn't work:
<cfif IsDefined("cfStruct.EMAILS")>
<cfloop from="1" to="5" index="i">
<cfif StructKeyExists( cfStruct.EMAILS, '#i#' ) >
<cfset setVariable( "EMAIL_#i#", "#cfStruct.EMAILS.i#" >
<cfelse>
<cfset setVariable( "EMAIL_#i#", '') >
</cfif>
</cfloop>
<cfelse>
Could you please help me to solve the problem?
Regards,
I believe the cleanest was to write this is:
<cfloop from="1" to="5" index="i">
<cfif StructKeyExists( cfStruct.EMAILS, i ) >
<cfset variables["EMAIL_#i#"] = cfStruct.EMAILS[i] >
<cfelse>
<cfset variables["EMAIL_#i#"] = '' >
</cfif>
</cfloop>
For the following reasons:
No unnecessary string expressions. Every time you do '#i#' you're telling CF to parse the string, evaluate the expressions within it, and return a new string in place of this one..
Explicit is better than implicit, using variables["EMAIL_#i#"] tells you exactly where you've put the variable you're creating so when you come to re-read months later it's crystal clear what's going on.
Bonus
If you change your loop to <cfloop from="1" to="#structCount(cfStruct.EMAILS)#" index="i"> then your code won't create more variables than needed (if this effect is desired) and could scale up to any number struct values.
I solved the problem it was a syntax problem:
<cfloop from="1" to="5" index="i">
<cfif StructKeyExists( cfStruct.EMAILS, '#i#' ) >
<cfset setVariable( "EMAIL_#i#", "#cfStruct.EMAILS[i]#") >
<cfelse>
<cfset setVariable( "EMAIL_#i#", '') >
</cfif>
</cfloop>
Strictly speaking, you should use cfStruct.EMAILS["#i#"] instead of "#cfStruct.EMAILS[i]#". That is,
<cfloop from="1" to="5" index="i">
<cfif StructKeyExists( cfStruct.EMAILS, "#i#" ) >
<cfset setVariable( "EMAIL_#i#", cfStruct.EMAILS["#i#"]) >
<cfelse>
<cfset setVariable( "EMAIL_#i#", '') >
</cfif>
</cfloop>
I am getting an error after upgrade from coldfusionOX to coldfusion 10.
Error Occurred While Processing Request Complex object types cannot be
converted to simple values.
The expression has requested a variable or an intermediate expression
result as a simple value. However, the result cannot be converted to a
simple value. Simple values are strings, numbers, boolean values, and
date/time values. Queries, arrays, and COM objects are examples of
complex values. The most likely cause of the error is that you tried
to use a complex value as a simple one. For example, you tried to use
a query variable in a cfif tag.
It occurs at line " cfloop index="local.thisRight" list="#rights#" ". It seems like ColdFusion does not like the "rights" here.
Anyone can give me some help? Thanks so much.
<cfif local.profile.rights.profile.self is not "">
<cfquery name="local.getAffiliations" datasource="#Request.readerDSN#">
SELECT tblPersonsToAffiliations.affiliationID, tblPersonsToAffiliations.rights, tblAffiliations.affiliationType, tblPersonsToAffiliations.relationshipType
FROM tblPersonsToAffiliations INNER JOIN tblAffiliations
ON tblPersonsToAffiliations.affiliationID = tblAffiliations.affiliationID
WHERE tblPersonsToAffiliations.personID IN (#local.profile.rights.profile.self#)
AND (tblPersonsToAffiliations.archived IS NULL
OR tblPersonsToAffiliations.archived = '')
</cfquery>
<cfif local.getAffiliations.recordCount is not 0>
<cfloop query="local.getAffiliations">
<cfif local.getAffiliations.relationshipType is "interested">
<cfset local.thisRelationshipType = "provisionalMember">
<cfif IsDefined("local.profile.rights.#affiliationType#.#local.thisRelationshipType#")>
<cfset local.profile.rights[affiliationType][local.thisRelationshipType] = ListAppend(local.profile.rights[affiliationType][local.thisRelationshipType], affiliationID)>
<cfelse>
<cfset local.profile.rights[affiliationType][thisRelationshipType] = affiliationID>
</cfif>
<cfelse>
<cfset local.thisRelationshipType = "fullMember">
<cfif IsDefined("local.profile.rights.#affiliationType#.#local.thisRelationshipType#")>
<cfset local.profile.rights[affiliationType][local.thisRelationshipType] = ListAppend(local.profile.rights[affiliationType][local.thisRelationshipType], affiliationID)>
<cfelse>
<cfset local.profile.rights[affiliationType][local.thisRelationshipType] = affiliationID>
</cfif>
<cfif isNull(rights)>
<cfelse>
<cfloop index="local.thisRight" list="#rights#" >
<cfif IsDefined("local.profile.rights.#affiliationType#.#local.thisRight#")>
<cfset local.profile.rights[affiliationType][local.thisRight] = ListAppend(local.profile.rights[affiliationType][local.thisRight], affiliationID)>
<cfelse>
<cfset local.profile.rights[affiliationType][local.thisRight] = affiliationID>
</cfif>
</cfloop>
</cfif>
</cfif>
</cfloop>
</cfif>
</cfif>
A bit earlier in your code you do this:
<cfif local.getAffiliations.relationshipType is "interested">
I think you need the same query name prefix in front of "rights" that is used when evaluating "relationshipType".
Try this:
#local.getAffiliations.rights#
HTH!
I am betting it is failing on this line:
<cfloop index="local.thisRight" list="rights" >
You are attempting to use the string "rights" as a list. My first reaction would be that you need to make that:
<cfloop index="local.thisRight" list="#rights#" >
Using the following query, I am trying to do a simple case here when the first record it encounters it should basically add "AND" and for the remaining conditions, I want to add OR
Here is my try
<cfif isDefined('age') and len(trim(age)) and age neq '-1'>
<cfset age = trim(htmlEditFormat(lcase(age)))>
<cfloop list="#age#" index="k">
or age between #ListFirst(k,'-')# and #ListLast(k,'-')#
</cfloop>
</cfif>
trying to make it work like this
and (age between 18 and 20
or age between 20 and 25
or age between 25 and 30)
I am not getting where I should add a condition to add parenthesis and the AND operator.
You could do something as similar as adding a false statement and then looping through everything else as needed
<cfif isDefined('age') and len(trim(age)) and age neq '-1'>
<cfset age = trim(htmlEditFormat(lcase(age)))>
AND (1 = 2 --always returns false
<cfloop list="#age#" index="k">
OR age between #ListFirst(k,'-')# and #ListLast(k,'-')#
</cfloop>
)
</cfif>
This is what you were trying to do
<cfif isDefined('age') and len(trim(age)) and age neq '-1'>
<cfset age = trim(htmlEditFormat(lcase(age)))>
AND (
<cfloop list="#age#" index="k">
<cfif listFirst(age) NEQ k> OR </cfif> --if it's not the first iteration, add the OR
age between #ListFirst(k,'-')# and #ListLast(k,'-')#
</cfloop>
)
</cfif>
An alternative that doesn't require an if block and would work for any type of loop:
<cfif isDefined('age') and len(trim(age)) and age neq '-1'>
<cfset age = trim(htmlEditFormat(lcase(age)))>
<cfset expressionSeparator = "">
AND (
<cfloop list="#age#" index="k">
#expressionSeparator#
age between #ListFirst(k,'-')# and #ListLast(k,'-')#
<cfset expressionSeparator = " or ">
</cfloop>
)
</cfif>