Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

evaluate uniqueidentifier fieldname

Status
Not open for further replies.

krisplus5

Programmer
Oct 4, 2001
44
US
Hi all,

I'm stumped (or tired).
I'm looping through form.fieldnames and want to update the database record if the value of the field is not an empty string. However, the fieldnames are set dynamically using the record identifier such as:
UID_C823B934-932A-4A3F-935E-0D5B0345A71B
such that everything after the underscore is the uniqueidentifier of the record in SQL Server.

So to get the value of the field I'd generally do:
evaluate("form." & fld)

But because there are hyphens in the fieldname this fails with an invalid expression error. So I have to pass it with delayed evaluation as:
evaluate(de("form." & fld))

Now I'm not getting the value when I do this, just the fieldname again. I thought that DE was just supposed to pass it as a string to avoid the expression evaluation. What am I doing wrong?

All suggestions are much appreciated!

Cheers,
Kris
 
It's doing exactly what it's ment to. DE is Don't evaluate. if you tell it not to evaluate you're not going to get the value of the variable, it's goign to stop at just making the field Name.

try

<cfset temp = "form."&fld>
<cfoutput>evaluate(temp)</cfoutput>



A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
Hi Bomboy,

Thanks for the response, but DE() is for Delayed Evaluation, for specific use within Evaluate() and IIf(), where you want to pass a string that should not be evaluated as an expression, such as a string of characters that happen to have hyphens in it. I've also seen it used for delaying evaluation of content that contains CF variables, such as a stored template in a database.

In any case, simply using evaluate(temp) in the context you suggest does not work. It throws the same error because CF is trying to evaluate the uniqueidentifier which has hyphens in it, and mistakes this as a request to perform subtraction.

Still looking for an answer to this one. I know I must be missing something...

Cheers,
Kris
 
whatever the "D" stands for, it doesn't matter, that isn't your problem here.

Not knowing why I didn't pick up on this first is beyond me.

CF variable names can contain ONLY alphanumeric characters and the underscore. form.UID_C823B934-932A-4A3F-935E-0D5B0345A71B is an invalid variable name, you'll have to replace them with "_", remove them, or come up with a new naming convention. sorry

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
Hi bombboy,

Thanks for the info on variable naming. Definitely worth remembering.

In the end, I did not need to evaluate at all. I was able to solve this by abandoning dot notation. Simply using
form[UID_C823B934-932A-4A3F-935E-0D5B0345A71B]
rather than
form.UID_C823B934-932A-4A3F-935E-0D5B0345A71B
works fine.

Not sure how this relates to the illegal variable naming issue. Overthinking it again...

Cheers,
Kris
 
Very cool, I've never come across that problem before. I tried to look it up but couldn't find anything. I'm guessing since using it in the object/key notation it isn't restricted because it isn't a variable at that point. That's good to know as well. I wonder if MM did that on purpouse or if we'll soon experience a "fix" to the "bug"

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
in fact the onlything i can find is
livedocs said:
A structure's key must be a string. The values associated with the key can be any valid ColdFusion value or object. It can be a string or integer, or a complex object such as an array or another structure. Because structures can contain any kind of data they provide a very powerful and flexible mechanism for representing complex data.

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top