Skip to main content
August 23, 2011
Question

cfgrid edit working, delete is not working

  • August 23, 2011
  • 2 replies
  • 1391 views

When I select a row and try to delete it, I get "Error invoking CFC _admin_cfc_contacts.cfc : OK [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]"

Here is my cfgrid code...

<cfset args = structNew()>
<cfset args.name = "contact_grid">
<cfset args.format = "html">
<cfset args.query = "biz_contacts">
<cfset args.stripeRows = "yes">
<cfset args.bgcolor = "FFFFFF">
<cfset args.colheaderalign = "left">
<cfset args.colheaderbold = "yes">
<cfset args.delete = "yes">
<cfset args.griddataalign = "left">
<cfset args.multirowselect = "yes">
<cfset args.insert = "yes">
<cfset args.selectcolor = "FF6633">
<cfset args.height = "500">
<cfset args.selectmode = "edit">
<cfset args.autowidth = "yes">
<cfset args.onchange = "cfc:_admin_cfc_contacts.edit_grid({cfgridaction},{cfgridrow},{cfgridchanged})">

<div style="padding-top: 20px; padding-left: 20px; padding-right: 20px;">
    <cfform name="test">
    <cfgrid attributeCollection="#args#">
        <cfgridcolumn name="id" display="false">
        <cfgridcolumn name="business_name" header="Biz Name">
        <cfgridcolumn name="name" header="Contact Name">
        <cfgridcolumn name="address" header="Address">
        <cfgridcolumn name="link" header="Link">
        <cfgridcolumn name="city" header="City">
        <cfgridcolumn name="state" header="State">
        <cfgridcolumn name="phone" header="Phone">
        <cfgridcolumn name="email" header="Email">
        <cfgridcolumn name="website" header="Website">
        <cfgridcolumn name="contacted" header="Contacted">
    </cfgrid>
    </cfform>
</div>

And here is my .cfc code...

<cffunction name="edit_grid" access="remote">

    <cfargument name="gridaction" type="string" required="yes">
    <cfargument name="gridrow" type="struct" required="yes">
    <cfargument name="gridchanged" type="struct" required="yes">

    <cfset var colname = "">
    <cfset var value = "">
   
    <cfswitch expression="#arguments.gridaction#">

        <!--- update --->
        <cfcase value="U">
            <cfset colname = StructKeyList(arguments.gridchanged)>
            <cfset value = arguments.gridchanged[colname]>
            <cfquery datasource="mydsn">
            UPDATE mytable
            SET #colname# = '#value#'
            WHERE id = <cfqueryparam value="#arguments.gridrow.id#" cfsqltype="cf_sql_integer">
            </cfquery>
        </cfcase>
   
        <!--- delete --->
        <cfcase value="D">
            <cfquery datasource="mydsn">
            DELETE FROM mytable
            WHERE id = <cfqueryparam value="#arguments.gridrow.id#" cfsqltype="cf_sql_integer">
            </cfquery>
        </cfcase>

    </cfswitch>

</cffunction>

    This topic has been closed for replies.

    2 replies

    Participant
    February 22, 2013

    Did you ever resolve this issue?

    I know your post is pretty old, now - I'm old, too - but I had the same problem and, I think, for the same reason.

    I also think I just found a fix, that I can't recall having been shared in any of my recent searches on this topic.

    Using your cfc code, these are comments and these are revisions ...

    <cffunction name="edit_grid" access="remote">

        <cfargument name="gridaction" type="string" required="yes">
        <cfargument name="gridrow" type="struct" required="yes">
        <cfargument name="gridchanged" type="struct" required="yes">

        <cfset var colname = "">
        <cfset var value = "">

        <!--- *** Add/init' this variable; name it whatever_works_for_you. *** --->
         <cfset var row_pk_id = ""/>     


        <cfswitch expression="#arguments.gridaction#">

            <!--- update --->
            <cfcase value="U">
                <cfset colname = StructKeyList(arguments.gridchanged)>
                <cfset value = arguments.gridchanged[colname]>

              <!--- *** Add this statement to assign the value from "my_pk_column"; `id` in this case, but it was `quantity_tracking_id` in my case. *** --->

             <cfset row_pk_id = arguments.gridrow.id />
                <cfquery datasource="mydsn">
                UPDATE mytable
                SET #colname# = '#value#'

              <!--- *** Change this line ... *** --->

              <!---
                WHERE id = <cfqueryparam value="#arguments.gridrow.id#" cfsqltype="cf_sql_integer">

              --->

              <!--- *** ... to this. *** --->

              WHERE id = <cfqueryparam value = "#row_pk_id#" cfsqltype="cf_sql_integer">
                </cfquery>
            </cfcase>
       
            <!--- delete --->
            <cfcase value="D">

                   <!--- *** Likewise ... *** --->

                  <cfset row_pk_id = arguments.gridrow.id />
                <cfquery datasource="mydsn">
                DELETE FROM mytable

              <!--- *** ... and ... *** --->

              <!---
                WHERE id = <cfqueryparam value="#arguments.gridrow.id#" cfsqltype="cf_sql_integer">

                   --->

               WHERE id = <cfqueryparam value = "#row_pk_id#" cfsqltype = "cf_sql_integer">
                </cfquery>
            </cfcase>

        </cfswitch>

    </cffunction>

    I am unable to do little more than a weak SWAG at the why of the failure with the former and success with the latter, but, when I changed one line of code in the cfquery, my updates began working.

    My expertise is, shall we say, limited, perhaps "wading-depth", at best, but, while trying to figure it out yesterday ...

    • I located the point-of-failure, the query, even though the err_msg was SO different from any cfquery/SQL fault message I've yet seen.
    • I tried to look at and understand (a bit more of the former than the latter, to be sure) the debugging content generated by Firebug, which seemed to have more to do with the inability to find a resource; I think it was a something.gif.
    • I saw that the resource was sought in a folder (our folks) installed (wisely or not) under the CFIDE folder.
    • I know that our folks had recently locked down access to CFIDE,as well as any of its "children", cfgrid libraries/resources included.
    • I knew that, after the lockdown, our folks created some sort of virtual-folder when I asked them to make the cfgrid functionality available to us again.

    Well, all this started me wondering about what, exactly, was going on that would fit into this particular scenario.

    That's when I looked at the query again and wondered if the issue might be direct use/reference in the cfquery of values residing in the more-complexly-structured arg's.  So, I decided to try what I suggest above, assignment to a simple variable and use of that variable in the cfquery.

    I'm sure that there are plenty of way-deeper folk than I who could go into particulars.

    I'm just tickled that I'm "back in business"!

    HTH,

    Steve in Memphis

    Inspiring
    August 23, 2011
    When I select a row and try to delete it, I get "Error invoking CFC _admin_cfc_contacts.cfc : OK [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]"

    And did you do what it suggested?

    --

    Adam

    August 23, 2011

    That never works.