How to add a row to two tables using one add row button in CAF Webmethods

function createRow()
{
var tableModel = CAF.model("#{caf:cid(‘defaultForm:BenodigSomerTable’)}");

	var rowCount = tableModel.getRowCount();

	alert(rowCount + 1);
    row = tableModel.insertRow();
	alert(rowCount);

}
the above code is in the click event of my add row button for a table named SomerTable. My intention is to add a row on table SomerTable as well as BenodigSomerTable using just one add row button.my code wont execute the line between the two alerts.
Anything I can do to achieve this.

There is no insertRow() method in the client-side Table Model.

You would want to use the tableModel.add(…) method if you want to add a row on the client-side.

For example, something like this:


var tableModel = CAF.model("#{caf:cid('defaultForm:BenodigSomerTable')}"); 
//add new row the as the first row of the table
tableModel.add(0, {});
1 Like

Hi Eric Norman, my problem its when add the json on the second parameter tableModel.add(0, {}); whats its the structure, my example its:
var values={
EMPLOYEE_ID: “1234”,//EMPLOYEE_ID
FIRST_NAME: “My FName”,//FIRST_NAME
DEPARTMENT_NAME: “Dep” //DEPARTMENT_NAME
};
But not working, any solution for this?

Regarts.

The syntax should be something like this to populate the values of controls in the new row at the same time the row is added:


var tableModel = CAF.model("#{caf:cid('defaultForm:BenodigSomerTable')}");   
tableModel.add(0, 
    {
        //for the values field, the key is the controlId, and the value is the value
        values : {
            htmlInput1 : 'My new row',
            htmlInput2: 'value2'
       }
    });

Thanks a lot, but my code:

var tableAsync13=CAF.model(‘jsfwmp8485:defaultForm:asyncTable’);
tableAsync13.add(0, {
values : {
htmlOutputText2: ‘1234’,//EMPLOYEE_ID
htmlOutputText4: ‘My Name’,//FIRST_NAME
htmlOutputText6: ‘Dep’ //DEPARTMENT_NAME
}
});

But still yet not working, there are something wrong?, my row it put to table but empty.

Double check if your Output Text controls are configured with the “Raw” property set to false. A raw output text control does not render the tag around the text so there isn’t a client-side id to match to the equivalent key in your JSON block.

Alternatively, if you are just populating client-side labels in the columns and not binding it to any input controls, then you could instead just populate the labels of each table cell with this alternate syntax:


var tableModel = CAF.model("#{caf:cid('defaultForm:BenodigSomerTable')}");     
tableModel.add(0, {
  //the index of string in the array corresponds to the index of the cell in the new row
  label : [
      'My new row',
      'My new row2'
  ]
});