I thought I had this one licked...
But I can't seem to get it tracked down...
Funny thing is - the list delete function works... And performs the desired task...
But I still get this error...
Invalid list index 0. In function ListDeleteAt(list, index [, delimiters]), the value of index, 0, is not a valid as the first argument (this list has 12 elements). Valid indexes are in the range 1 through the number of elements in the list. The error occurred on line 735.
Code below
<cfset pwlist = "#add.pwlist#">
<cfset curlist = "#add.pwlist#">
<cfset ud = "#session.demshinuser_id#">
<cfoutput>
#curlist#
<br>
<br>
#pwlist#
<br><br>
#ud#<br>
<cfset newlist = ListDeleteAt(curlist, ListFind(pwlist,ud,","), ",")> <-- Error Here
#newlist#
</cfoutput>
<cfquery name=Update DATASOURCE="#ds#">
update shindates
set
pwlist = '#newlist#'
where shinid = '#shinid#'
</cfquery>
<cfif src is "cpwupc">
<cflocation url="upc.cfm" addToken="no">
</cfif>
<cfif src is "hcpw">
<cflocation url="list.cfm?typeid=#add.typeid#" addToken="no">
</cfif>
Found on Goog - trying this too to check if it a bad list thing... and ud isn't in list in first place...
<cfset pos = listfind(pwlist,ud)>
<cfif pos>
do list delete
<cfelse>
error. element not found. do something else
</cfif>
Related
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#" >
I have a variable named #cfData# which contains an array of structures. As it's clear from the image, for 1st structure array there are 6 keys and for 2nd, only two keys,viz date and open.
If I run a common loop, to go through each and every key, I will get an error at second array element. So the following only works when all the keys are present in the structure:
<cfset blockedtotal = 0 />
<cfset bouncetotal = 0 />
<cfset blocked = 0/>
<cfset datetotal = 0 />
<cfloop array = #cfData# index = "i">
<cfset blockedtotal += i.blocked />
<cfset bouncetotal += i.bounce />
</cfloop>
After reading online, I got an idea of using StructKeyExists where I think I can proceed in the following way:
<cfif structKeyExists(cfData,"bounce")>
<cfoutput>Bounce:#cfData.bounce#"/></cfoutput>
<cfelse>
<cfoutput> Bounce : [none]<br/></cfoutput>
</cfif>
But I am wondering, where exactly should I insert the above code inside the cfloop? Please advise if my approach is wrong.
Update:
Thanks guys. I got it running by using the following code based on the answers and it's running fine:
<cfloop array="#cfData#" index="i">
<cfif structKeyExists(i, "date")>
<cfset counter++>
<cfoutput>#counter#</cfoutput> Date is: <cfoutput> #i.date#</cfoutput> <br/>
</cfif>
</cfloop>
you don't need a "common loop". You can loop through each struct with
<cfloop array="#cfData#" index="i">
<cfloop collection="#i#" item="key">
struct with key '#key#' has data: #i[key]#
</cfloop>
</cfloop>
Of, if you need to decide if the struct has certain key, do something:
<cfloop array="#cfData#" index="i">
<cfif structKeyExists(i, "someKey")>
<cfset counter++>
</cfif>
</cfloop>
I need to efficiently search ranges of integers in ColdFusion. These ranges have different lengths and they can have "holes" (they are not continuous).
I thought that a Java TreeMap called from ColdFusion would be a efficient solution. However, I sadly discovered that the TreeMap is alphabetically ordered and I need numeric order. I tried to apply the JavaCast function to the key of the map but it didn't work. Apparently, ColdFusion was expecting the key to be a String and not an Int.
Here is the sample code (without the JavaCast attempt) to illustrate my situation:
<!--- Create the TreeMap --->
<cfset map = createObject("java", "java.util.TreeMap").init()>
<!--- Add Ranges to it --->
<!--- From 1 to 3 return "Range 1". --->
<cfset t = StructNew()>
<cfset t.finish = JavaCast("int", 3)>
<cfset t.value = "Range 1">
<cfset map.put(1, t)><!--- This 1 is the one I tried to JavaCast --->
<!--- From 4 to 10 return "Range 2". --->
<cfset t = StructNew()>
<cfset t.finish = JavaCast("int", 10)>
<cfset t.value = "Range 2">
<cfset map.put(4, t)>
<!--- From 20 to 50 return "Range 3". --->
<cfset t = StructNew()>
<cfset t.finish = JavaCast("int", 50)>
<cfset t.value = "Range 3">
<cfset map.put(20, t)>
<!--- From 75 to 80 return "Range 4". --->
<cfset t = StructNew()>
<cfset t.finish = JavaCast("int", 80)>
<cfset t.value = "Range 4">
<cfset map.put(75, t)>
<!--- Debug. Output the Map content --->
<cfoutput>Debug - Ordered map: #map.toString()#</cfoutput><br />
<!--- Search number --->
<cfset key = 9>
<cfset entry = map.floorEntry(key)>
<!--- Debug. Output entry found --->
<cfoutput>Debug - Entry found: #entry#</cfoutput><br />
<!--- Debug. Output result --->
<cfif isNull(entry)>
<cfoutput>Too small</cfoutput>
<cfelseif key lte entry.getValue().finish>
<cfoutput>Debug - Result: #entry.getValue().value#</cfoutput>
<cfelse>
<cfoutput>Too large</cfoutput>
</cfif>
And this is the output generated by the code above:
Debug - Ordered map: {1={FINISH={3},VALUE={Range 1}}, 20={FINISH={50},VALUE={Range 3}}, 4={FINISH={10},VALUE={Range 2}}, 75={FINISH={80},VALUE={Range 4}}}
Debug - Entry found: 75={FINISH={80},VALUE={Range 4}}
Debug - Result: Range 4
When I was expecting it to be:
Debug - Ordered map: {1={FINISH={3},VALUE={Range 1}}, 4={FINISH={10},VALUE={Range 2}}, 20={FINISH={50},VALUE={Range 3}}, 75={FINISH={80},VALUE={Range 4}}}
Debug - Entry found: 4={FINISH={10},VALUE={Range 2}}
Debug - Result: Range 2
So my question here is, what do I have to do to get the TreeMap working as I want, which is, with numeric order?
By the way, I'm using ColdFusion 9.
Thank you very much!
(From comments)
Very first thing that comes to mind is you are not casting all of the key values as integers, so they are treated as strings when the TreeMap performs its comparisons. That would explain why floorEntry returns the wrong results. It is comparing strings, not integers. Try casting all of the keys as integers, and it should work as expected.
<cfset map.put( javacast("int", 1), t)>
...
<cfset map.put( javacast("int", 75), t)>
<cfset key = 9>
<cfset entry = map.floorEntry( javacast("int", key) )>
I trying to use a very simple CFGRID (with CFGRIDUPDATE) but not allow NULLS.
<cfset strWarning= "">
<cfif IsDefined("FORM.gridEntered")>
<cfif FORM.myName EQ '' OR FORM.myURL EQ ''>
<cfset strWarning= "Error: Form fields cannot be blank">
<cfelse>
<cfgridupdate grid="gridSomething"
dataSource="qryTSQL" tableName="tblName" keyOnly="Yes">
</cfif>
</cfif>
<cfoutput>#strWarning#</cfoutput><br />
<cfform>
<cfgrid name="gridSomething" query="qryTSQL"
selectMode="Edit" format="HTML">
<cfgridcolumn name = "myID" display="No">
<cfgridcolumn name = "myName">
<cfgridcolumn name = "myURL">
</cfgrid>
<cfinput type="submit" name="gridEntered">
The error I am getting is - Error Diagnostics: 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.
I think I am under thinking this desired solution.
Thanks.
EDIT: Updated Error Message
Error Diagnostics: Element MYURL is undefined in FROM.
Form scope - struct
FIELDNAMES GRIDENTERED,__CFGRID__CFFORM_1__GRIDSOMETHING
GRIDENTERED Submit Query
GRIDSOMETHING.MYID Form scope - array
1 1001
GRIDSOMETHING.MYURL Form scope - array
1 /test_d.cfm
GRIDSOMETHING.ORIGINAL.MYID Form scope - array
1 1001
GRIDSOMETHING.ORIGINAL.MYURL Form scope - array
1 /changed.cfm
GRIDSOMETHING.ROWSTATUS.ACTION Form scope - array
1 U
__CFGRID__CFFORM_1__GRIDSOMETHING __CFGRID__EDIT__=2 MYID Y MYURL Y 1 U 1001 1001 /test_d.cfm /changed.cfm
Grids work differently than standard FORM fields. Since grids contain multiples rows of data, CF creates arrays of the new/changed values. One for each grid column ie
FORM.gridname.columnName
To determine if any of the values for a specific column are empty, you need to loop through the array for that column and check each value:
<cfset updateCount = arrayLen(FORM.gridSomething.myName) />
<cfloop from="1" to="#updateCount#" index="x">
<cfset nameValue = trim( FORM.gridSomething.myName[x] ) />
<cfset urlValue = trim( FORM.gridSomething.myURL[x]) ) />
<!--- one or both of the values is empty --->
<cfif not len( nameValue ) OR not len( urlValue )>
... empty value found. do something here ....
</cfif>
</cfloop>
Add this function to you code and call it passing it the FORM scope as follows;
On page or CFC works the same!
Clears up errors with some versions of CF that choke on blank cols in a simple grid update
<cffunction name="cleanGridUpdate" >
<cfargument name="FORM" >
<cfloop collection="#FORM#" item="thisOne">
<cftry>
<cfset thisDeep = arrayLen(FORM[thisOne])>
<cfloop index="x" from="1" to="#thisDeep#">
<cfif len(FORM[thisOne][x])lt 1>
<cfset FORM[thisOne][x] = javaCast( "null", 0 )>
</cfif>
</cfloop>
<cfcatch>
<cfset cat=1>
</cfcatch>
</cftry>
</cfloop>
<cfreturn form>
</cffunction>
<cfif isDefined('URL.action') AND URL.action eq 'gridUpdate'>
<cfset cleanGridUpdate(FORM)>
<cfgridupdate grid="#URL.table#" table="#URL.table#" datasource="your_DS"
keyonly="yes" >
</cfif>
<cfform action="##?action=gridUpdate&table=cheesePuffs" method="post">
<cfgrid name='cheesePuffs' format='HTML'/>
<cfinput name="submit" type="submit" value>
</cfform>
I have the below code:
<cfset abcList = "*,B,b,A,C,a">
<cfset abcList=ListToArray(abcList,',')>
When I output 'abcList' then it is giving me a value but when I use the 'abcList' in <cfif> it's not working. Here is the code which is creating the problem:
<cfoutput>
#abcList[1]# <!---This is giving '*' as Correct o/p--->
<cfif #abcList[1]# eq '*'> <!---Here its going in else--->
list has * at first place
<cfelse>
* is not first
</cfif>
</cfoutput>
Any suggestions on what's wrong in my code?
You don't necessarily need to convert the list to an array. If you are starting from a list variable, you may use Coldfusion list functions to do the same thing without specifying the array conversion.
<cfset abcList = "*,B,b,A,C,a">
<cfif Compare(listGetAt(abcList, 1), '*') EQ 0>
Match
<cfelse>
No Match
</cfif>
Note that most of Coldfusion's string comparisons are not case sensitive. So if you need to test that 'B' is not the same as 'b', you will need to use the compare() function or else use one of the Regular Expression string functions. In this case, compare() returns 0 if string 1 equals string 2. If you do not need case sensitivity, then you may simplify further:
<cfset abcList = "*,B,b,A,C,a">
<cfif listGetAt(abcList, 1) EQ '*'>
Match
<cfelse>
No Match
</cfif>
It also works fine for me. Perhaps you have some extra spaces in the list values? That would skew the results:
<cfset abcList = "#chr(32)#*,B,b,A,C,a">
<cfset abcList=ListToArray(abcList,',')>
<cfoutput>
The value of abcList[1] = #abcList[1]# <br/>
<cfif abcList[1] eq '*'>
list has * at first place
<cfelse>
The else condition was hit because abcList[1] is "(space)*" and not just "*"
</cfif>
</cfoutput>
Try trimming the value first. Also, the # signs around the value are not needed.
<cfif trim(abcList[1]) eq '*'>
....
</cfif>
If that does not work, display the ascii values of both characters. Perhaps they are different than you are thinking.
<cfoutput>
ASCII abcList[1] = #asc(abcList[1])# <br/>
ASCII "*" = #asc("*")# <br/>
</cfoutput>
<cfset abcList = "*,B,b,A,C,a">
<cfset abc=ListToArray(abcList)>
<cfif #abc[1]# eq "*">OK<cfelse>FAIL</cfif>
<cfif abc[1] eq "*">OK<cfelse>FAIL</cfif>
Prints "OK OK" for me. Can you re-confirm it prints something else for you?