hi,
I have created an page having mater and detail type of things. Master region have some page items and detail has interactive grid. Now while saving I use ajax callback process. There are two process one for master table and the other one is for detail table. Both process being called with one button called "Save" having dynamic action with true action as javascript code. following is master process.
apex.server.process( 'insert_master',
{ pageItems:'#P16_DATE,#P16_TYPE,#P16_MID',
x01: $v('P16_DATE'),
x02: $v('P16_TYPE'),
x03: $v('P16_MID')
}, // Parameter to be passed to the server
{
success: function (pData) { // Success
console.log(pData);
//$s('P16_MID',pData.mid);
$s('P16_NUMBER',pData.vno);
},
error: function(e){
console.log("Error: ", e);
},
dataType: "json" // Response type
}
);
and process is as below
declare
cont int;
vno int;
begin
/*select nvl(max(mid),0)+1 into cont from vouchermst;*/
select nvl(max(vnumber),0)+1 into vno from vouchermst where yearid = :yid and vdate = apex_application.g_x01
and vtype = apex_application.g_x02 ;
insert into vouchermst (mid,vdate,vtype,vnumber,yearid,userid,fdate,status)
values(apex_application.g_x03,apex_application.g_x01,apex_application.g_x02,vno,:yid,:uid,sysdate,'N');
:masterid := cont;
apex_json.open_object;
apex_json.write('mid', apex_application.g_x03);
apex_json.write('vno', vno);
apex_json.close_all;
exception when no_data_found then
null;
end;
this process insert data into master table and return vno as voucher number. It works fine.
below is second javasceipt true action righ after above true action.
var model = apex.region("detail").widget().interactiveGrid("getViews", "grid").model;
var cont = 0;
col_c001 = model.getFieldKey("MID");
col_c002 = model.getFieldKey("ACC_CODE");
col_c003 = model.getFieldKey("NARRATION");
col_c004 = model.getFieldKey("DEBIT");
col_c005 = model.getFieldKey("CREDIT");
col_c006 = model.getFieldKey("SRNO");
model.forEach(function (igrow) {
apex.item("P16_ACC_CODE").setValue(igrow[col_c002].v);
apex.item("P16_NARRATION").setValue(igrow[col_c003]);
apex.item("P16_DEBIT").setValue(igrow[col_c004]);
apex.item("P16_CREDIT").setValue(igrow[col_c005]);
apex.item("P16_SRNO").setValue(cont+1);
cont = cont+1;
apex.server.process( 'insert_detail',
{ pageItems:'#P16_MID,#P16_ACC_CODE,#P16_NARRATION,#P16_DEBIT,#P16_CREDIT,#P16_SRNO',
x01: $v('P16_MID'),
x02: $v('P16_ACC_CODE'),
x03: $v('P16_NARRATION'),
x04: $v('P16_DEBIT'),
x05: $v('P16_CREDIT'),
x06: $v('P16_SRNO')
}, // Parameter to be passed to the server
{
success: function (pData) { // Success
console.log($v('x01'));
console.log($v('x02'));
/*apex.item('P16_MID').setValue(pData.mid);
apex.item('P16_NUMBER').setValue(pData.vno);*/
},
error: function(e){
console.log("Error: ", e);
},
dataType: "json" // Response type
});
});
below is process for above true action
declare
mid int;
ac varchar2(11);
nar varchar2(250);
deb number(14,2);
cre number(14,2);
sr int;
begin
mid := apex_application.g_x01;
ac := apex_application.g_x02;
nar := apex_application.g_x03;
deb := apex_application.g_x04;
cre := apex_application.g_x05;
sr := apex_application.g_x06;
/*insert into voucherdtl
values(1,apex_application.g_x02,apex_application.g_x03,
apex_application.g_x04,apex_application.g_x05,apex_application.g_x06);*/
insert into voucherdtl values(mid,ac,nar,deb,cre,sr);
exception when no_data_found then
null;
end;
ok. now the problem is if I call both process with single button it some time insert data into detail table and some time it does not and some time it show error Fk error but every time data into master table inserted successfully.
I than tried and created two buttons one for master and second for detail data to insert. It is working as required. Now my question is how to put them under one button and get reliable result from it.
hope to have your quick and positive response.
Vinish Kapoor
Instead of two dynamic actions to execute JS code, write both codes into one JS code.
First for insert_master and then below for insert_detail.
Try it.
Abdul Aqeel Malik
thanks for your reply. I shall give this try.
I am looping through interactive grid and read and put row data on page item one by one and insert into table. Is there way to insert data directly from interactive grid into table with the help of ajax callback coz I don't want to submit page.
Abdul Aqeel Malik
I have tried and its working. Thanks
Abdul Aqeel Malik
I have done according to your instructions and its working now.
Moving forward as I am new to oracle apex, I want the value of page
item should be selected so if user input some value it should be written
on the value otherwise user has to remove value than type new one.
Abdul Aqeel Malik
if I check console it shows following error with single button with two ajax callback process.
"sqlerrm:ORA-02291: integrity constraint (NOONERP.VOUCHERDTL_FK1) violated - parent key not found\n"
but same code works fine if I put single process to single button.
afzal
use nested ajaxcallback process in single js code-- like--
apex.server.process( 'insert_master',
{ pageItems:'#P16_DATE,#P16_TYPE,#P16_MID',
x01: $v('P16_DATE'),
x02: $v('P16_TYPE'),
x03: $v('P16_MID')
}, // Parameter to be passed to the server
{
success: function (pData) { // Success
console.log(pData);
//$s('P16_MID',pData.mid);
$s('P16_NUMBER',pData.vno);
///----------detail table code -----------------
var model = apex.region("detail").widget().interactiveGrid("getViews", "grid").model;
var cont = 0;
col_c001 = model.getFieldKey("MID");
col_c002 = model.getFieldKey("ACC_CODE");
col_c003 = model.getFieldKey("NARRATION");
col_c004 = model.getFieldKey("DEBIT");
col_c005 = model.getFieldKey("CREDIT");
col_c006 = model.getFieldKey("SRNO");
model.forEach(function (igrow) {
apex.item("P16_ACC_CODE").setValue(igrow[col_c002].v);
apex.item("P16_NARRATION").setValue(igrow[col_c003]);
apex.item("P16_DEBIT").setValue(igrow[col_c004]);
apex.item("P16_CREDIT").setValue(igrow[col_c005]);
apex.item("P16_SRNO").setValue(cont+1);
cont = cont+1;
apex.server.process( 'insert_detail',
{ pageItems:'#P16_MID,#P16_ACC_CODE,#P16_NARRATION,#P16_DEBIT,#P16_CREDIT,#P16_SRNO',
x01: $v('P16_MID'),
x02: $v('P16_ACC_CODE'),
x03: $v('P16_NARRATION'),
x04: $v('P16_DEBIT'),
x05: $v('P16_CREDIT'),
x06: $v('P16_SRNO')
}, // Parameter to be passed to the server
{
success: function (pData) { // Success
console.log($v('x01'));
console.log($v('x02'));
/*apex.item('P16_MID').setValue(pData.mid);
apex.item('P16_NUMBER').setValue(pData.vno);*/
},
error: function(e){
console.log("Error: ", e);
},
dataType: "json" // Response type
});
});
//--end nested ajaxcallback process
},
error: function(e){
console.log("Error: ", e);
},
dataType: "json" // Response type
}
);
----------------------------
var model = apex.region("detail").widget().interactiveGrid("getViews", "grid").model;
var cont = 0;
col_c001 = model.getFieldKey("MID");
col_c002 = model.getFieldKey("ACC_CODE");
col_c003 = model.getFieldKey("NARRATION");
col_c004 = model.getFieldKey("DEBIT");
col_c005 = model.getFieldKey("CREDIT");
col_c006 = model.getFieldKey("SRNO");
model.forEach(function (igrow) {
apex.item("P16_ACC_CODE").setValue(igrow[col_c002].v);
apex.item("P16_NARRATION").setValue(igrow[col_c003]);
apex.item("P16_DEBIT").setValue(igrow[col_c004]);
apex.item("P16_CREDIT").setValue(igrow[col_c005]);
apex.item("P16_SRNO").setValue(cont+1);
cont = cont+1;
apex.server.process( 'insert_detail',
{ pageItems:'#P16_MID,#P16_ACC_CODE,#P16_NARRATION,#P16_DEBIT,#P16_CREDIT,#P16_SRNO',
x01: $v('P16_MID'),
x02: $v('P16_ACC_CODE'),
x03: $v('P16_NARRATION'),
x04: $v('P16_DEBIT'),
x05: $v('P16_CREDIT'),
x06: $v('P16_SRNO')
}, // Parameter to be passed to the server
{
success: function (pData) { // Success
console.log($v('x01'));
console.log($v('x02'));
/*apex.item('P16_MID').setValue(pData.mid);
apex.item('P16_NUMBER').setValue(pData.vno);*/
},
error: function(e){
console.log("Error: ", e);
},
dataType: "json" // Response type
});
});
afzal
sorry , there is something wrong in above code, ignore that , use this one--
use nested ajaxcallbackprocess in single js code like--
apex.server.process( 'insert_master',
{ pageItems:'#P16_DATE,#P16_TYPE,#P16_MID',
x01: $v('P16_DATE'),
x02: $v('P16_TYPE'),
x03: $v('P16_MID')
}, // Parameter to be passed to the server
{
success: function (pData) { // Success
console.log(pData);
//$s('P16_MID',pData.mid);
$s('P16_NUMBER',pData.vno);
///----------detail table code -----------------
var model = apex.region("detail").widget().interactiveGrid("getViews", "grid").model;
var cont = 0;
col_c001 = model.getFieldKey("MID");
col_c002 = model.getFieldKey("ACC_CODE");
col_c003 = model.getFieldKey("NARRATION");
col_c004 = model.getFieldKey("DEBIT");
col_c005 = model.getFieldKey("CREDIT");
col_c006 = model.getFieldKey("SRNO");
model.forEach(function (igrow) {
apex.item("P16_ACC_CODE").setValue(igrow[col_c002].v);
apex.item("P16_NARRATION").setValue(igrow[col_c003]);
apex.item("P16_DEBIT").setValue(igrow[col_c004]);
apex.item("P16_CREDIT").setValue(igrow[col_c005]);
apex.item("P16_SRNO").setValue(cont+1);
cont = cont+1;
apex.server.process( 'insert_detail',
{ pageItems:'#P16_MID,#P16_ACC_CODE,#P16_NARRATION,#P16_DEBIT,#P16_CREDIT,#P16_SRNO',
x01: $v('P16_MID'),
x02: $v('P16_ACC_CODE'),
x03: $v('P16_NARRATION'),
x04: $v('P16_DEBIT'),
x05: $v('P16_CREDIT'),
x06: $v('P16_SRNO')
}, // Parameter to be passed to the server
{
success: function (pData) { // Success
console.log($v('x01'));
console.log($v('x02'));
/*apex.item('P16_MID').setValue(pData.mid);
apex.item('P16_NUMBER').setValue(pData.vno);*/
},
error: function(e){
console.log("Error: ", e);
},
dataType: "json" // Response type
});
});
//--end nested ajaxcallback process
},
error: function(e){
console.log("Error: ", e);
},
dataType: "json" // Response type
}
);
Abdul Aqeel Malik
yes its working now. thanks
Vinish Kapoor
Welcome back Afzal. Thank you.