11 Replies Latest reply on Jul 26, 2007 1:16 PM by GeorgeWS

    Insert/Update DB

    GeorgeWS Level 1
      I have a form:

      private function sendFormdata():void {
      var myobj:Object = new Object();
      myobj.itemid = itemid.text;
      myobj.programtype = programtype.data
      myobj.trackcomp = trackcomp.selected;
      cfdataInsert.addData({user:myobj})
      }

      //itemid is a TextInput, programtype is a ComboBox, trackcomp is a Checkbox

      When I fill in the form it works fine to insert the records using a CFC. I just have one argument and then the insert:

      <cffunction name="addData" access="remote" output="false" hint="I insert data" returntype="void">
      <cfargument name="user" type="struct" required="true" />
      <cfquery datasource="DB">
      insert into Programs
      (ItemID, ProgramType,TrackComp)
      values
      (' '#user.ItemID#','#user.ProgramType#', '#user.TrackComp#')
      </cfquery>
      </cffunction>

      The ItemId and TrackComp work great! but the combobox does nothing. What am I missing? I was thinking the variable in the CFC should be something like this: <cfqueryparam cfsqltype="cf_sql_char" value="#user.ProgramType#" />
      BUT NO GO.

      Can anyone help me?
      Thanks
      George
        • 1. Re: Insert/Update DB
          BLXWebMaster Level 1
          Are you trying to capture the label?

          If so, use "programtype.selectedLabel"

          • 2. Re: Insert/Update DB
            GeorgeWS Level 1
            Im not sure where you mean to put that?
            Thanks for the response

            George
            • 3. Re: Insert/Update DB
              BLXWebMaster Level 1
              You have
              private function sendFormdata():void {
              var myobj:Object = new Object();
              myobj.itemid = itemid.text;
              myobj.programtype = programtype.data
              myobj.trackcomp = trackcomp.selected;
              cfdataInsert.addData({user:myobj})
              }

              If you are trying to capture the selected item label use...
              var myobj:Object = new Object();
              myobj.itemid = itemid.text;
              myobj.programtype = programtype.selectedLabel; // This will capture the selected item.
              myobj.trackcomp = trackcomp.selected;
              cfdataInsert.addData({user:myobj})
              }
              • 4. Re: Insert/Update DB
                GeorgeWS Level 1
                Awsome. I tried a few things to pass the data. But Im not to smart. So my next question is how do you pass the data?

                Thanks again,
                George
                • 5. Re: Insert/Update DB
                  BLXWebMaster Level 1
                  Post your complete code (what you have so far) and I will modify it for you. Also, add a brief description of exactly what you are trying to do.



                  • 6. Re: Insert/Update DB
                    GeorgeWS Level 1
                    Here is what I have so far. I had taken fields out to make it easier to read befor. I am just making a form and submitting the choices. SUPER EASY (I would think, but ever control has something special about it.) I have InputBoxes, CheckBoxs, and ComboBoxs. I just want to add to a DB table and instead of the LABEL from the Comboboxs I want the DATA. I have had experience with other applications that I built that the length of the DB table field matters when filtering data (a function I will be adding later). What I mean is the length of the LABEL would have to be exactally the same for the filterFunction to work properly.

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">

                    <mx:Script>
                    <![CDATA[
                    private function sendFormdata():void {
                    var myobj:Object = new Object();
                    myobj.supplierid = supplierid.text;
                    myobj.supplier = supplier.text;
                    myobj.suppliercontact = suppliercontact.text;
                    myobj.customer = customer.text;
                    myobj.sequence = sequence.text;
                    myobj.rep = rep.text;
                    myobj.city = city.text;
                    myobj.itemid = itemid.text;
                    myobj.item = item.text;
                    myobj.timing = timing.text;
                    myobj.programtype = programtype.selectedLabel;
                    myobj.status = status.selectedLabel;
                    myobj.priority = priority.selectedLabel;
                    myobj.descrip = descrip.text;
                    myobj.followup = followup.selected;
                    myobj.followup = followup.selected;
                    myobj.trackcomp = trackcomp.selected;
                    myobj.preslocal = preslocal.selected;
                    myobj.tracksales = tracksales.selected;
                    myobj.followdates = followdates.text;
                    cfdataInsert.addData({user:myobj})
                    }

                    [Bindable]
                    public var theProgramType: Array = [ {label:"Program Type", data:1},
                    {label:"Drink Feature", data:"DF"}, {label:"Well Placement", data:"WP"},
                    {label:"Back Bar Placement", data:"BBP"}, {label:"WBTG", data:"WBTG"},
                    {label:"Wine Menu Placement", data:"WMP"}, {label:"Other", data:"Other"} ];

                    [Bindable]
                    public var theStatus: Array = [ {label:"Status", data:1},
                    {label:"Optional", data:"O"}, {label:"Mandatory", data:"M"} ];

                    [Bindable]
                    public var thePriority: Array = [ {label:"Priority", data:1},
                    {label:"A-Key Supplier Initiative", data:"A"}, {label:"B-Development Program", data:"B"}, {label:"C-Other", data:"C"} ];

                    [Bindable]
                    public var selectedItem:Object;
                    ]]>
                    </mx:Script>

                    <mx:RemoteObject
                    id="cfdataInsert" showBusyCursor="true"
                    destination="ColdFusion"
                    source="youngsmarket.programs.national.nataccprograms.bin.nataccprograms">
                    </mx:RemoteObject>

                    <mx:VBox>
                    <mx:HBox>
                    <mx:FormItem label="Supplier ID" id="SupplierID"
                    horizontalAlign="left">
                    <mx:TextInput id="supplierid" editable="true" enabled="true" width="75"/>
                    </mx:FormItem>
                    <mx:FormItem label="supplier" id="Supplier">
                    <mx:TextInput id="supplier" width="75"/>
                    </mx:FormItem>
                    <mx:FormItem label="Supplier Contact" id="SupplierContact">
                    <mx:TextInput id="suppliercontact" width="75"/>
                    </mx:FormItem>
                    </mx:HBox>

                    <mx:HBox>
                    <mx:FormItem label="National Account" id="Customer"
                    horizontalAlign="left">
                    <mx:TextInput id="customer" editable="true" enabled="true" width="75"/>
                    </mx:FormItem>
                    <mx:FormItem label="Seq" id="Sequence"
                    horizontalAlign="left">
                    <mx:TextInput id="sequence" editable="true" enabled="true" width="75"/>
                    </mx:FormItem>
                    <mx:FormItem label="Account Executive" id="Rep"
                    horizontalAlign="left">
                    <mx:TextInput id="rep" editable="true" enabled="true" width="75"/>
                    </mx:FormItem>
                    </mx:HBox>

                    <mx:HBox>
                    <mx:FormItem label="City" id="City"
                    horizontalAlign="left">
                    <mx:TextInput id="city" editable="true" enabled="true" width="75"/>
                    </mx:FormItem>
                    </mx:HBox>

                    <mx:HBox>
                    <mx:FormItem label="Item ID" id="ItemID"
                    horizontalAlign="left">
                    <mx:TextInput id="itemid" editable="true" enabled="true" width="75"/>
                    </mx:FormItem>
                    <mx:FormItem label="Item" id="Item"
                    horizontalAlign="left">
                    <mx:TextInput id="item" editable="true" enabled="true" width="75"/>
                    </mx:FormItem>

                    <mx:FormItem label="Timing" id="Timing"
                    horizontalAlign="left">
                    <mx:TextInput id="timing" editable="true" enabled="true" width="75"/>
                    </mx:FormItem>
                    <mx:FormItem label="Program Type" id="ProgramType">
                    <mx:ComboBox id="programtype" dataProvider="{theProgramType}" width="125"
                    close="selectedItem=ComboBox(event.target).selectedItem"/>
                    </mx:FormItem>
                    <mx:FormItem label="Status" id="Status">
                    <mx:ComboBox id="status" dataProvider="{theStatus}" width="125"
                    close="selectedItem=ComboBox(event.target).selectedItem"/>
                    </mx:FormItem>
                    <mx:FormItem label="Priority" id="Priority">
                    <mx:ComboBox id="priority" dataProvider="{thePriority}" width="125"
                    close="selectedItem=ComboBox(event.target).selectedItem"/>
                    </mx:FormItem>
                    <mx:FormItem label="Desc" id="Descrip"
                    horizontalAlign="left">
                    <mx:TextInput id="descrip" editable="true" enabled="true" width="75"/>
                    </mx:FormItem>
                    <mx:FormItem label="Follow-up" id="FollowUp">
                    <mx:CheckBox id="followup" enabled="true"/>
                    </mx:FormItem>
                    <mx:FormItem label="Track Comp" id="TrackComp">
                    <mx:CheckBox id="trackcomp" enabled="true"/>
                    </mx:FormItem>
                    <mx:FormItem label="Present Locally" id="PresLocal">
                    <mx:CheckBox id="preslocal" enabled="true"/>
                    </mx:FormItem>
                    <mx:FormItem label="Track Sales" id="TrackSales">
                    <mx:CheckBox id="tracksales" enabled="true"/>
                    </mx:FormItem>
                    <mx:FormItem label="Follow Up Dates" id="FollowDates"
                    horizontalAlign="left">
                    <mx:TextInput id="followdates" editable="true" enabled="true" width="75"/>
                    </mx:FormItem>
                    </mx:HBox>

                    <mx:FormItem id="FI_BTN_send">
                    <mx:Button label="Send" id="BTN_Send" click="sendFormdata()"
                    enabled="true" labelPlacement="right"/>
                    </mx:FormItem>
                    </mx:VBox>

                    </mx:Application>

                    Thanks

                    George
                    • 7. Re: Insert/Update DB
                      BLXWebMaster Level 1
                      I will whip something up. Working on something, give me an hour or so.

                      • 8. Re: Insert/Update DB
                        BLXWebMaster Level 1
                        This is how I woudl go about it. Your example passed a struct to the CFC. I prefer individual strings. Makes it easier to debug, but you can see how to modify if you want. Also, since you are using CF, I would check out Mappings and how to use them in Flex, might make it easier and certainly more portable.

                        Let me know if you have any questions.
                        <?xml version="1.0" encoding="utf-8"?>
                        <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">

                        <mx:Script>
                        <![CDATA[
                        import mx.collections.*;
                        import mx.events.*;
                        import mx.controls.*;
                        import mx.collections.XMLListCollection;
                        import mx.rpc.events.*;

                        private function sendFormdata():void {
                        nataccprograms.InsertData.send();
                        }

                        [Bindable]
                        public var theProgramType: Array = [ {label:"Program Type", data:1},
                        {label:"Drink Feature", data:"DF"}, {label:"Well Placement", data:"WP"},
                        {label:"Back Bar Placement", data:"BBP"}, {label:"WBTG", data:"WBTG"},
                        {label:"Wine Menu Placement", data:"WMP"}, {label:"Other", data:"Other"} ];

                        [Bindable]
                        public var theStatus: Array = [ {label:"Status", data:1},
                        {label:"Optional", data:"O"}, {label:"Mandatory", data:"M"} ];

                        [Bindable]
                        public var thePriority: Array = [ {label:"Priority", data:1},
                        {label:"A-Key Supplier Initiative", data:"A"}, {label:"B-Development Program", data:"B"}, {label:"C-Other", data:"C"} ];

                        [Bindable]
                        public var strResult:String;
                        private function addDataReceived(event:ResultEvent):void{
                        strResult=event.result as String;
                        Alert.show(strResult);
                        }
                        ]]>
                        </mx:Script>

                        <mx:RemoteObject id="nataccprograms" showBusyCursor="true" destination="ColdFusion" source="youngsmarket.programs.national.nataccprograms.bin.nataccprograms">
                        <mx:method name="addData" result="addDataReceived(event)">
                        <mx:arguments>
                        <supplierid>{supplierid.text}</supplierid>
                        <supplier>{supplier.text}</supplier>
                        <suppliercontact>{suppliercontact.text}</suppliercontact>
                        <customer>{suppliercontact.text}</customer>
                        <sequence>{sequence.text}</sequence>
                        <rep>{rep.text}</rep>
                        <city>{city.text}</city>
                        <itemid>{itemid.text}</itemid>
                        <item>{item.text}</item>
                        <programtype>{programtype.selectedItem.data}</programtype>
                        <status>{status.selectedItem.data}</status>
                        <priority>{priority.selectedItem.data}</priority>
                        <descrip>{descrip.text}</descrip>
                        <followup>{followup.selected}</followup>
                        <trackcomp>{trackcomp.selected}</trackcomp>
                        <preslocal>{preslocal.selected}</preslocal>
                        <tracksales>{tracksales.selected}</tracksales>
                        <followdates>{followdates.text}</followdates>
                        </mx:arguments>
                        </mx:method>
                        </mx:RemoteObject>

                        <mx:Canvas x="10" y="20" width="686" height="289">
                        <mx:FormItem label="Supplier ID" id="SupplierID" horizontalAlign="left" y="10">
                        <mx:TextInput id="supplierid" editable="true" enabled="true" width="75"/>
                        </mx:FormItem>
                        <mx:FormItem label="supplier" id="Supplier" y="40">
                        <mx:TextInput id="supplier" width="75"/>
                        </mx:FormItem>
                        <mx:FormItem label="Supplier Contact" id="SupplierContact" y="70">
                        <mx:TextInput id="suppliercontact" width="75"/>
                        </mx:FormItem>
                        <mx:FormItem label="National Account" id="Customer" horizontalAlign="left" x="206" y="10">
                        <mx:TextInput id="customer" editable="true" enabled="true" width="75"/>
                        </mx:FormItem>
                        <mx:FormItem label="Seq" id="Sequence" horizontalAlign="left" x="206" y="40">
                        <mx:TextInput id="sequence" editable="true" enabled="true" width="75"/>
                        </mx:FormItem>
                        <mx:FormItem label="Account Executive" id="Rep" horizontalAlign="left" x="206" y="70">
                        <mx:TextInput id="rep" editable="true" enabled="true" width="75"/>
                        </mx:FormItem>
                        <mx:FormItem label="City" id="City" horizontalAlign="left" y="190">
                        <mx:TextInput id="city" editable="true" enabled="true" width="75"/>
                        </mx:FormItem>
                        <mx:FormItem label="Item ID" id="ItemID" horizontalAlign="left" y="10" x="441">
                        <mx:TextInput id="itemid" editable="true" enabled="true" width="75"/>
                        </mx:FormItem>
                        <mx:FormItem label="Item" id="Item" horizontalAlign="left" y="40" x="442">
                        <mx:TextInput id="item" editable="true" enabled="true" width="75"/>
                        </mx:FormItem>
                        <mx:FormItem label="Timing" id="Timing" horizontalAlign="left" x="0" y="130">
                        <mx:TextInput id="timing" editable="true" enabled="true" width="75"/>
                        </mx:FormItem>
                        <mx:FormItem label="Program Type" id="ProgramType" x="206" y="160">
                        <mx:ComboBox id="programtype" dataProvider="{theProgramType}" width="125"/>
                        </mx:FormItem>
                        <mx:FormItem label="Status" id="Status" x="206" y="100">
                        <mx:ComboBox id="status" dataProvider="{theStatus}" width="125"/>
                        </mx:FormItem>
                        <mx:FormItem label="Priority" id="Priority" x="206" y="130">
                        <mx:ComboBox id="priority" dataProvider="{thePriority}" width="125"/>
                        </mx:FormItem>
                        <mx:FormItem label="Desc" id="Descrip" horizontalAlign="left" x="0" y="100">
                        <mx:TextInput id="descrip" editable="true" enabled="true" width="75"/>
                        </mx:FormItem>
                        <mx:FormItem label="Follow-up" id="FollowUp" x="442" y="126">
                        <mx:CheckBox id="followup" enabled="true"/>
                        </mx:FormItem>
                        <mx:FormItem label="Track Comp" id="TrackComp" x="442" y="74">
                        <mx:CheckBox id="trackcomp" enabled="true"/>
                        </mx:FormItem>
                        <mx:FormItem label="Present Locally" id="PresLocal" x="442" y="100">
                        <mx:CheckBox id="preslocal" enabled="true"/>
                        </mx:FormItem>
                        <mx:FormItem label="Track Sales" id="TrackSales" x="442" y="152">
                        <mx:CheckBox id="tracksales" enabled="true"/>
                        </mx:FormItem>
                        <mx:FormItem label="Follow Up Dates" id="FollowDates" horizontalAlign="left" x="0" y="160">
                        <mx:TextInput id="followdates" editable="true" enabled="true" width="75"/>
                        </mx:FormItem>
                        <mx:Button label="Send" id="BTN_Send" click="sendFormdata()" enabled="true" labelPlacement="right" x="78" y="234"/>
                        </mx:Canvas>
                        </mx:Application>
                        • 9. Re: Insert/Update DB
                          BLXWebMaster Level 1
                          Message Lenght Exceeded, neede two posts.

                          nataccprograms.cfc
                          <cfcomponent>
                          <cffunction name="InsertData" access="remote" output="false" hint="I insert data" returntype="string">
                          <cfargument name="supplierid" required="false" />
                          <cfargument name="supplier" required="false" />
                          <cfargument name="suppliercontact" required="false" />
                          <cfargument name="customer" required="false" />
                          <cfargument name="sequence" required="false" />
                          <cfargument name="rep" required="false" />
                          <cfargument name="city" required="false" />
                          <cfargument name="itemid" required="false" />
                          <cfargument name="item" required="false" />
                          <cfargument name="programtype" required="false" />
                          <cfargument name="status" required="false" />
                          <cfargument name="priority" required="false" />
                          <cfargument name="descrip" required="false" />
                          <cfargument name="followup" required="false" />
                          <cfargument name="trackcomp" required="false" />
                          <cfargument name="preslocal" required="false" />
                          <cfargument name="tracksales" required="false" />
                          <cfargument name="followdates" required="false" />
                          <cfquery datasource="DB">
                          insert into Programs
                          (ItemID, ProgramType,TrackComp)
                          values
                          ('#Arguments.itemid#','#Arguments.programtype#', '#Arguments.trackcomp#')
                          </cfquery>
                          <cfreturn "Record Inserted">
                          </cffunction>
                          </cfcomponent>

                          Allen
                          • 10. Re: Insert/Update DB
                            peterdoyle
                            Hi,

                            Trying to use your example as it seems to do exactly what I want. However when I run the example I get:

                            Element ITEMID is undefined in ARGUMENTS.

                            I have tried a number of different variations but cant get past this.

                            Any help would be greatly appreciated. Using 7.0.2 and flex 2.0.1

                            Cheers
                            Peter
                            • 11. Re: Insert/Update DB
                              GeorgeWS Level 1
                              Allen,
                              I have this all working. I ofcourse need to make more improvements. I have added a datagrid that has a combobox filter to filter the grid and a column that has a checkbox I want the ones that get a check to get added to the DB along with the form field you helped me out with before.

                              Thanks for all your help.

                              George