So I've got an IG which can have a list of serial numbers. I have written some javascript to auto populate the IG with all all possible serial numbers. The javascript works fine if the IG is empty and has no pre-existing values. However, if the IG has one or two serial numbers already populated, and I run my autopopulate function, it will overwrite the previous two values with all the other values I'm populating. So essentially the two values seemingly disappear from my list. Essentially I want this function to append to the list, not overwrite it. I thought that is what the javascript would do when inserting a new row, but again, if there is a pre-existing row…. it gets clobbered by the function. I've included the javscript below to insert the rows. For any IG gurus, maybe someone can look at the function and tell me what I'm doing wrong.
function autofill_sn() {
var widget = apex.region('IG_SN').widget();
var grid = widget.interactiveGrid('getViews','grid');
var model = grid.model;
var myJSONString = $v("P345_SN_INFO_JSON"); – this is a list of serial nums not already in IG
var myObject = JSON.parse(myJSONString); model.clearData();
alert(myJSONString);
for ( var i = 0; i < myObject.length; i++) {
var obj = myObject[i];
//insert new record on a model
var myNewRecordId = model.insertNewRecord();
//get the new record
var myNewRecord = model.getRecord(myNewRecordId);
//update record values
model.setValue(myNewRecord, 'SN_ID', obj.serial_no);
};
}