Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Trouble saving from ComboBoxItem -- aka how do I re-write the save criteria

    This is a save problem with the comboBoxItem discussed in this thread: http://forums.smartclient.com/forum/...endant-selects

    When I call save on the list grid in the previous thread I get

    Criteria received from the client for add operation is missing the following non-sequence primary key fields: [id_Rooms].

    This is a case of the form returning citeria fields that don't match what is needed by the parent grid.

    The cirteria that is failing has:
    {id_People:<id_People>,
    buildingNameShort:<code_Buildings>,
    roomNumber:<id_Rooms>
    }

    A correct save to the parent grid needs:
    {id_People:<id_People>,
    id_Rooms:<id_Rooms>}

    So I'm looking for a way to get the comboBoxItemt to emit the criteria in a correct format, or else have the save function be able to re-fomat the citeria before attempting the save.

    Hopefully there is some simple call that I'm missing here.

    Using: SmartClient_v110p_2017-05-15_PowerEdition

    Thanks
    Russ Poyner

    #2
    We don't really follow the question - in that other thread you are providing a getPickListCriteria() function so you have complete control over the criteria already.

    You also haven't explained in what circumstance you are "saving" the criteria, but if it's a DataSource operation, there is also DataSource.transformRequest() as a point where you could modify it.

    Comment


      #3
      The error is generated when I call saveAllEdits on spaceAssignGrid, or if I have autoSaveEdits:true and hit enter to save the form.

      Is it appropriate to use DataSource.transformRequest() on a datasource that is bound to an SQL table with the isomorphic, java server code? The examples I saw in the documentation seemed to refer to DataSources that were accessing outside REST or http type sources.

      I thought the pickListCriteria was just used to filter the list bound to the comboBoxItem. Is it the same criteria that get's sent to the DataSource when saveAllEdits is called?

      It's slightly confusing that the parent grid and the 2 comboBoxes are bound to 3 different datasources with overlapping field names. The grid is actually bound to an SQL view that combines a simple many-to-many table where the keys are id_People and id_Rooms with some descriptive fields from the rooms and buildings tables. Each room has primary key id_Rooms and is linked to a building by foreign key code_Buildings. The many to many table assigns each person to zero or more rooms.

      The hoped for work flow is: Operator clicks the Assign new room button which calls spaceAssignGrid.startEditingNew({id_People:<id of currentPerson>}) for the person we are working on. She then selects the building and room she wants to assign to the person and hits enter or a save button which saves a new id_Person, id_Room pair. to the table.





      isc.ListGrid.create({
      ID:"spaceAssignGrid",
      autoDraw:false,
      autoFetchData:true,
      dataSource:"roomAssignments",
      canEdit:true,
      confirmCancelEditing:false,
      confirmDiscardEdits:false,
      autoSaveEdits:false,
      editorExit: function(editCompletionEvent, record, newValue, rowNum, colNum, grid) {
      console.log("event",editCompletionEvent,"record",record,"value",newValue,"row",rowNum,"col",colNum,"grid",grid);
      if(editCompletionEvent === "enter") {
      saveRoomButton.saveSpaceAssignGrid();
      }
      },
      fields:[
      {
      hidden:true,
      canEdit:false,
      name:"id_People"
      },
      {
      hidden:true,
      canEdit:false,
      name:"id_Rooms"
      },
      {
      hidden:true,
      canEdit:false,
      name:"code_Buildings",
      width:57
      },
      {
      name:"buildingNameShort",
      editorType:"ComboBoxItem",
      editorProperties : {
      optionDataSource:"buildings",
      displayField:"buildingNameShort",
      valueField:"code_Buildings"
      }
      },
      {
      name:"roomNumber",
      width:70,
      editorType:"ComboBoxItem",
      editorProperties:{
      optionDataSource:"rooms",
      getPickListFilterCriteria : function () {
      var selectedBuilding = this.grid.getEditedRecord(this.rowNum);
      return {
      code_Buildings:selectedBuilding.buildingNameShort,
      roomNumber:this.getEnteredValue()
      };
      },
      displayField:"roomNumber",
      valueField:"id_Rooms",
      },
      },
      {
      hidden:true,
      canEdit:false,
      name:"buildingNameLong"
      },
      {
      name:"roomTypeFull",
      canEdit:false
      },
      {
      name:"roomSubtype",
      canEdit:false
      },
      {
      hidden:true,
      canEdit:false,
      name:"roomProgram"
      },
      {
      hidden:true,
      canEdit:false,
      name:"roomDescription"
      },
      {
      hidden:true,
      canEdit:false,
      name:"roomNotes"
      },
      {
      hidden:true,
      canEdit:false,
      name:"roomAreaSqFt"
      },
      {
      hidden:true,
      canEdit:false,
      name:"occupantCapacity"
      },
      {
      hidden:true,
      canEdit:false,
      name:"buildingNameAbbreviated",
      width:70
      },
      {
      hidden:true,
      canEdit:false,
      name:"buildingNotes"
      }
      ],
      canEdit:true,
      })

      isc.Button.create({
      ID:"assignRoomButton",
      top:535,
      autoFit:true,
      title:"Assign New Room",
      click: function() {
      var record = peopleListGrid.getSelectedRecord();
      spaceAssignGrid.startEditingNew({id_People:record.id_People});
      }
      })

      isc.Button.create({
      ID:"saveRoomButton",
      top:535,
      autoFit:true,
      title:"Save",
      click: function() {this.saveSpaceAssignGrid()},

      saveSpaceAssignGrid: function() {
      console.log("Got save");
      var row = spaceAssignGrid.getEditRow();
      var record = spaceAssignGrid.getEditedRecord(row);
      console.log("editRow",row,"record",record);
      spaceAssignGrid.saveAllEdits();
      peopleDetailTabs.updateDetails();
      }
      })

      isc.VLayout.create({
      ID:"spaceAssignVLayout",
      autoDraw:false,
      members:[
      spaceAssignGrid,
      assignRoomButton,
      saveRoomButton
      ]
      })

      Comment


        #4
        DataSource.transformRqeuest() applies to any DataSource type. If it didn't, the docs would tell you so.

        What would normally be saved is the valueField, in this case the value of id_Rooms in the record from the related "rooms" DataSource. If you are seeing the criteria in the values being saved, something is going wrong, but just an override of getPickListFilterCriteria() wouldn't create this problem, as that's very ordinary and common.

        So whatever is going wrong does not appear to be in this code, but if you suspect a framework bug, you can try working toward a test case. That will likely reveal the actual cause along the way.

        Comment


          #5
          So maybe this is a framework bug. If I understand correctly the saved record should contain the value fields plus other assigned fields. Which would be {id_People:<id of person being edited>,code_Building:<code of chosen building>,id_Rooms:<id of room assigned>}. In the code above the last console.log statement (under saveRoomButton) prints the value of the record obtained by calling getEditedRow.

          The console.log output:
          editRow 2 record
          Object {id_People: 10193, buildingNameShort: "0408", roomNumber: 10034}
          buildingNameShort : "0408"
          id_People : 10193
          roomNumber : 10034
          __proto__ : Object
          types number number

          In the output above we have the value of the valuefield assigned to the display field.
          buildingNameShort: <code_Building>
          roomNumber;<id_Rooms>

          buildingNameShort for code_Building 0408 is "Engr Hall"
          roomNumber for id_Rooms 10034 is "2037"

          If you agree with me that this looks like a framework bug let me know and I'll work on a shorter example to submit as a bug.

          Comment


            #6
            What a comboBox saves is the value of the valueField from the related record, saved in the form values under the name of the comboBoxItem. So in your case we would expect to see the value of the id_Rooms field from the related record assigned to the name of the comboBox, which is roomNumber. So no indication of a framework bug in your logs, nor any hint of how you are getting the criteria as part of the saved values.

            We do still recommend that you work toward a test case so you can discover the cause.

            Comment


              #7
              It took a while to sink in, but I got this part. The grid field has to be named for the field you want to save in the database and you use displayField to get it to show the value of another, user friendly field. My mistake was trying to do the displayField/valueField indirection at the level of the comboBox instead of the parent grid field.

              This code now generates a record that *should* work:
              {
              name:"code_Buildings",
              title:"Building",
              width:80,
              displayField:"buildingNameShort",
              valueField:"code_Buildings",
              editorType:"ComboBoxItem",
              editorProperties : {
              optionDataSource:"buildings"
              }
              },
              {
              name:"id_Rooms",
              title:"Room #",
              width:50,
              editorType:"ComboBoxItem",
              displayField:"roomNumber",
              valueField:"id_Rooms",id
              editorProperties:{
              optionDataSource:"rooms",
              getPickListFilterCriteria : function () {
              var selectedBuilding = this.grid.getEditedRecord(this.rowNum);
              return {
              code_Buildings:selectedBuilding.code_Buildings,
              roomNumber:this.getEnteredValue()
              };
              },
              },
              },

              Comment

              Working...
              X