For Loop in Apex for Interactive GRID (json_arrayagg/JSON_ARRAY/JSON_OBJECT)
Dear All
As oracle forms developer we used to create cursor and based on cursor we have loop which will fetch the record from cursor and enter record in desired data block with asynch manor. Same functionality will be able to implement in Apex with help of json_arrayagg/JSON_ARRAY/JSON_OBJECT
1) Create Interactive Grid Region (Define Static ID like PODTL)
2) Create Parameter Static Region
--> P2_DOCNO Page item (Enter Document Number)
--> GET_RECORD Button Create Two true action.
1)Execute PL/SQL Code (First Action)
select (select json_arrayagg(json_array ( to_char(pi.docno), pi.srno,
JSON_OBJECT(KEY 'v' VALUE to_char(pi.prtcd) , KEY 'd' VALUE pi.prtcd),
JSON_OBJECT(KEY 'v' VALUE pi.unit , KEY 'd' VALUE pi.unit),
to_char(pi.xnqty), to_char(pi.xnrate),to_char(pi.xnval)
)
FORMAT JSON ORDER BY pi.srno desc RETURNING CLOB)
from purdtl pi where docno=:P2_DOCNO group by docno )
into :P2_GET_JSONDATA
from dual ;
2) Excute JavaScript
Get_Record();
3) Function and Global Variable Declaration
function Get_Record()
{
//change the ig_js_insert with the static id of your interactive grid
var widget = apex.region('PODTL').widget();
console.log('IG widget : ' + apex.region('PODTL').widget());
var grid = widget.interactiveGrid('getViews','grid');
var model = grid.model;
// Get JSON Data from Query
var JSONContractData = JSON.parse($v('P2_GET_JSONDATA'));
// Loop Over JSONData and Assing Values to Respective Column
$.each(JSONContractData, function (index, value) {
//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, 'DOCNO', value[0]);
model.setValue(myNewRecord, 'SRNO', value[1]);
model.setValue(myNewRecord, 'PRTCD', value[2]);
model.setValue(myNewRecord, 'UNIT', value[3]);
model.setValue(myNewRecord, 'XNQTY', value[4]);
model.setValue(myNewRecord, 'XNRATE', value[5]);
model.setValue(myNewRecord, 'XNVAL', value[6]);
});
}
Comments
Post a Comment