Announcement

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

    How to get the data back from add

    I have two different data sources on my page. I am trying to obtain the id key of the object I am adding to the db after my first update operation on the page. My code looks something like this:

    <code>
    isc.IButton.create({
    ID: "saveButton",
    title: "Save",
    layoutAlign: "right",
    wrap: true,
    click: function () {
    iptForm.saveData();
    wstWbsTree.saveAllEdits();
    }
    });
    </code>

    <code>
    public PrgIptTO add(PrgIptTO ipt, DSRequest dsRequest) {

    //save ipt

    return ipt;
    }
    </code>

    Now before I invoke wstWbsTree.saveAllEdits();, I would like to have iptForm.saveData() pass back the id that has just been generated for the new record and pass it into wstWbsTree.saveAllEdits();. How would I be able to do so?

    #2
    The data returned by the server's add/update operation is available in the client-side callback as 'data' or dsResponse.data. So:

    Code:
    isc.IButton.create({
        ID: "saveButton",
        title: "Save",
        layoutAlign: "right",
        wrap: true,
        click: function () {
            // call the server, when this operation completes, have
            // saveDataCallback() be invoked with whatever data the server
            // sent back.
            iptForm.saveData(this.getID()+".saveDataCallback(data)");
        },
        saveDataCallback : function (data) {
            // data is whatever you returned via dsResponse.setData() on the
            // server, so you can pull the generated id out of this object - for
            // example:
            var id = data.id;
    
            // send all pending updates in one HTTP request
            isc.RPCManager.startQueue();
    
            // get all the edited rows, patch on our id and save the rows
            var editRowNums = wstWbsTree.getAllEditRows(); 
            for (var i = 0; i < editRowNums.length; i++) {
                var row = wstWbsTree.getEditedRecord(editRowNums[i]);
                // patch in our id
                row.iptId = id;
                wstWbsTree.updateData(row);
            }
    
            //actually calls the server
            isc.RPCManager.sendQueue();
        }
    });

    Comment


      #3
      Ah, got it. I remember this part. Thanks!

      Comment


        #4
        Thanks. Got it to work. I got an internal error "too much recursion", which from what I have gathered from other threads on the forum, is a known issue with TreeGrid in 5.6. I was able to work around it, but just fyi.

        Comment


          #5
          Good to hear - thanks for the feedback and thanks for searching the forums :)

          Comment

          Working...
          X