2 Replies Latest reply on Aug 30, 2006 2:59 PM by KomputerMan.com

    <mx:RemoteObject.../> and deleting a record

    KomputerMan.com Level 1
      I am using a RemoteObject call to a CFC which is working pretty well at this time. I am able to add, modify and delete records. One enhancement I need to make is if I try to delete a record that I shouldn't be able to delete due to relational integrity issues, I.E. deleteing a record that is related to another record in another table, I need to display a message to the user teling them the record can not be deleted.

      If I try to delete a record that the database will not let me delete I can get a generic error message the will freak out my end users. Because of that I put in some code into the CFC that prevents the CFC from attempting to delete a record that it shouldn't. Problem is if the end user tries to delete a recrod that can not be deleted how do I return something (a popup window) back from my CFC telling them the record can't be deleted at this time?

      Right now the code that calls the RemoteObject looks like this (it does use a custom event to pass in variables).

      private function secTypeAddedHandler(event:SecTypeAddEvent):void // this is the listener for the add new sec type event.
      {
      getAllSecStuff.addSecRole(event.secTypeToAdd); // Pass the event with the variables to the CFC method addSecRole.
      getAllSecStuff.getSecRoles(); // refresh the data
      }

      <!-- Call the WebService -->
      <mx:RemoteObject id="getAllSecStuff" destination="ColdFusion" source="ISIF.WebServices.Flex.SecRoles" showBusyCursor="true">
      <mx:method name="getSecRoles" result="getSecRolesHandler(event)"/>
      </mx:RemoteObject>


      My CFC looks a little like this:
      <cffunction name="addSecRole" access="remote" returntype="string">
      <cfargument name="sectype" type="struct" required="yes">
      <CFSET MyReturnString = "">
      <CFIF STUFFTO ADD...>
      <CFQUERY... to add data>
      <CFELSE STUFF TO MOD>
      <CFQUERY... modify data>
      <CFELSE>
      <CFIF to find out if I can delete or not>
      <CFQUERY DEL THE DATA>
      <CFELSE>
      <CFSET MyReturnString = "No Can Do">
      </CFIF>
      </CFIF>

      <cfreturn MyReturnString>
      </cffunction>

      I guess my big question is I know the CFC is returning a string variable. How do I tell Flex to look at that value? If the returned string is set to "No can do" then I want to display a popup window telling the user that they can not delete this record because it is associated to another record. If the returned string is set to "" I don't want to do anything.

      Thanks in advance for the help!!!

      Have an Ordinary Day...
      KomputerMan ~|:-)


        • 1. Re: &lt;mx:RemoteObject.../&gt; and deleting a record
          rottmanja
          In your results function you can create an alert window. I assume you are not retuning a confimation string from your add/edit/valid delete results. But you can do it something like this.

          private function getSecRolesHandler(event:ResultEvent){

          if(event.result.length <= 0 ){
          Alert.show(event.result);
          }
          • 2. &lt;mx:RemoteObject.../&gt; and deleting a record
            KomputerMan.com Level 1
            Actually I am trying to return a string from the add / mod / delete function. The only reason I make the getSecRolesHandler
            call is to refresh my datagrid to show what changes have been made.

            I guess what I am looking for is how to I see what is being returned by the getAllSecStuff.addSecRole(event.secTypeToAdd); call. Does it show I am pretty new to Actionscript 3???

            So after a bit more digging I found I needed to add a result call to my RemoteObject call. So now my code looks like this:
            <mx:RemoteObject id="getAllSecStuff" destination="ColdFusion" source="ISIF.WebServices.Flex.SecRoles" showBusyCursor="true" result="getSecRoleEventStatus(event)">

            Then I created a function like so and life was good!!!
            [Bindable]
            private var MyUpDateResults:String=new String();

            private function getSecRoleEventStatus(event:ResultEvent):void
            {
            MyUpDateResults=event.result as String;
            if(MyUpDateResults == "ClassTmp" )
            {
            Alert.show('Unable to delete the security role because it is associated to a CF Template.', 'Can Not Delete The Record');
            }
            }

            Thanks for the help, you put me on the path to enlightenment!!!

            Have an Ordinary Day...
            KomputerMan ~|:-)