i am using this to add a check if the structfield ...
# cfml-general
g
i am using this to add a check if the structfield exists, then add else use null, it seems its still asking for name, do i need to add same type in the value <cfqueryparam cfsqltype="varchar" value="#formfields.name#" null="#NOT (structKeyExists(formfields, 'name') and len(trim(formfields.name)))#">
a
Your logic is :
NOT (structKeyExists(formfields, 'name') and len(trim(formfields.name)))
So it will be null if the key does not exist AND the value does not has len - both can not be true
I think you mean 'OR'
b
Apply the principle of "separation of concerns". For example:
<!--- Outside the cfquery tag --->
<cfset nameFieldDoesNotExist = NOT structKeyExists(formfields, 'name') OR len(trim(formfields.name)) eq 0>
<cfqueryparam cfsqltype="varchar" value="#formfields.name#" null="#nameFieldDoesNotExist#">