Discussions
Categories
- 196.8K All Categories
- 2.2K Data
- 239 Big Data Appliance
- 1.9K Data Science
- 450.3K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 544 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.8K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.5K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 439 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
Interactive Grid

Hello, I have a interactive grid. If no rows selected I want to display a error msg as 'No records selected'. If more than 1 record selected then display 'select 1 record'. If 1 row selected then call a procedure. How can I achieve this using Java Script?
Answers
-
Someone please help.
-
Hi,
If you want this to happen on DA on some button click - then
DA action - Execute JS
var gridView = apex.region("your-IG-static-id").widget().interactiveGrid("getViews").grid;
var records = gridView.getSelectedRecords();
var recs = records.length;
if (recs = 0) {apex.message.alert("No records selected")};
if (recs > 1) {apex.message.alert("Select 1 record")};
if (recs = 1) {
apex.server.process("CALL_YOUR_AJAX_PROCESS", {
x01: $v("PAGE_ITEM_1") ,// Parameters to pass to AJAX process if any
x02: $v("PAGE_ITEM_2") ,// Parameters to pass to AJAX process if any
}, {
//pageItems: ''
//dataType: 'text'
}).done(function (pData) {
console.log(pData);
});
};
Create an AJAX process and call your procedure there.
access the variables as apex_application.g_x01, apex_application.g_x02 ..etc
Thanks,
Veerendra.
-
Thanks a lot Veerendra. Can you also share how to display this error message in inline notification?
-
Hi,
You can try like below.
apex.message.clearErrors(); // Clear the previous errors if any.
apex.message.showErrors([ // This is an array
{
type: apex.message.TYPE.ERROR,
location: ["page", "inline"], // Remove Inline if the message is only at the Page level
pageItem: "P1_DEMO", /// This can be commented if you want to show the error only on Page level.
message: "Your error Message",
unsafe: false
}
]);
Thanks
-
Thank you. Can you please check this code. It is giving syntax error and I couldn't find what's wrong.
var gridView = apex.region("VALID").widget().interactiveGrid("getViews").grid;
var records = gridView.getSelectedRecords();
var recs = records.length;
apex.message.clearErrors();
if (recs = 0) // this is working fine
apex.message.showErrors([
{
type: apex.message.TYPE.ERROR,
location: ["page"],
message: "Please Select a Transaction",
unsafe: false
}
]);
if (recs > 1) // this is working fine
apex.message.showErrors([
{
type: apex.message.TYPE.ERROR,
location: ["page"],
message: "Please Select just one Transaction",
unsafe: false
}
]);
if (recs = 1) // this is not working. here based on the selection of a record I need to pass a column value to my AJAX process. column name is 'TRX_ID' and its a hidden column.
{
apex.server.process("manual_transmit", {
//x01: $v("P12_TRX_ID") // Parameters to pass to AJAX process if any
}, {
}).done(function (pData) {
console.log(pData);
});
};
AJAX process SQL:
DECLARE
l_username VARCHAR2(1000);
l_trx_id NUMBER;
l_error_msg VARCHAR2(1000);
l_reason VARCHAR2(1000);
l_val_only BOOLEAN DEFAULT TRUE;
v_url VARCHAR2(1000);
BEGIN
l_user_name := V('APP_USER');
v_url := apex_page.get_url(p_page => 50, p_items => :P50_TRX_ID, p_values => trx_id);
xxs2c_dsh_inv_list_pkg.mark_as_manual_transmission (l_username, l_trx_id, l_error_msg, l_reason, l_val_only);
IF l_error_msg IS NOT NULL
THEN
:P12_ERROR_MSG := l_error_msg;
ELSE
apex_util.redirect_url(p_url => v_url);
END IF;
END;
Please help.
-
Can anyone help me to get this please.
-
Hi,
Can you try below please?
function showErrorMessage(pMessage){
apex.message.showErrors([
{
type: apex.message.TYPE.ERROR,
location: ["page"],
message: pMessage,
unsafe: false
}
]);
}
var gridView = apex.region("VALID").widget().interactiveGrid("getViews").grid;
var records = gridView.getSelectedRecords();
var recs = records.length;
var trxID = 0;
apex.message.clearErrors();
if (recs = 0) showErrorMessage("Please Select a Transaction") // this is working fine
if (recs > 1) showErrorMessage("Please Select just one Transaction")// this is working fine
if (recs = 1) // this is not working
{
$.each(records , function(i, r) {
trxID = gridView.model.getValue(r, "TRX_ID");
});
apex.server.process("manual_transmit", {
x01: trxID // Parameters to pass to AJAX process if any
}, {
}).done(function (pData) {
console.log(pData);
if(pData.success == "ERROR") showErrorMessage(pData.message)
if(pData.success == "OK") apex.navigation.redirect(pData.message);
});
};
-- AJAX-----------------
DECLARE
l_username VARCHAR2(1000);
l_trx_id NUMBER;
l_error_msg VARCHAR2(1000);
l_reason VARCHAR2(1000);
l_val_only BOOLEAN DEFAULT TRUE;
v_url VARCHAR2(1000);
BEGIN
l_user_name := :APP_USER;
l_trx_id := to_number(apex_application.g_x01); -- Since you defined l_trx_id as NUMBER.
v_url := apex_page.get_url(p_page => 50, p_items => :P50_TRX_ID, p_values => l_trx_id);
xxs2c_dsh_inv_list_pkg.mark_as_manual_transmission (l_username, l_trx_id, l_error_msg, l_reason, l_val_only);
IF l_error_msg IS NOT NULL
THEN
apex_json.open_object;
apex_json.write('success', 'ERROR');
apex_json.write(message, l_error_msg);
apex_json.close_object;
ELSE
apex_json.open_object;
apex_json.write('success', 'OK');
apex_json.write(message, v_url);
apex_json.close_object;
END IF;
END;
Let me know if you have any issues.
Thanks,
-
Hello,
Thanks for your comment. This is still now working. When is select a row and press the button either it should throw an error or redirect to another page. Both are not happening. I see l_trx_id and v_return_url returing correct value. For testing just assigned those value into an item and checked. Really not sure where it is going wrong.
DECLARE
l_username VARCHAR2(1000);
l_trx_id NUMBER;
l_error_msg VARCHAR2(1000);
l_reason VARCHAR2(1000);
l_val_only BOOLEAN := true;
v_url VARCHAR2(1000);
l_message VARCHAR2(1000);
v_return_url varchar2(500) := null;
v_url_text varchar2(500) := null;
BEGIN
l_username := V('APP_USER');
l_trx_id := to_number(apex_application.g_x01); -- Since you defined l_trx_id as NUMBER.
--:P12_ERROR_MSG := l_trx_id;
--v_url := apex_page.get_url(p_page => 50, p_items => :P50_TRX_ID, p_values => l_trx_id);
v_url_text := 'f?p='||:APP_ID||':50:'||:APP_SESSION;
v_return_url := apex_util.prepare_url(v_url_text);
--:P12_COUNT := v_return_url;
xxs2c_dsh_inv_list_pkg.mark_as_manual_transmission (l_username, l_trx_id, l_error_msg, l_reason, l_val_only);
IF l_error_msg IS NOT NULL
THEN
apex_json.open_object;
apex_json.write('success', 'ERROR');
apex_json.write(l_message, l_error_msg);
apex_json.close_object;
ELSE
apex_json.open_object;
apex_json.write('success', 'OK');
apex_json.write(l_message, v_return_url);
apex_json.close_object;
END IF;
END;
-
Even the JS doesn't work. I used this.
var gridView = apex.region("VALID").widget().interactiveGrid("getViews").grid;
var records = gridView.getSelectedRecords();
var recs = records.length;
var trxID = 0;
alert(recs);
apex.message.clearErrors();
if (recs == 0)
apex.message.showErrors([
{
type: apex.message.TYPE.ERROR,
location: ["page"],
message: "Please Select a Transaction",
unsafe: false
}
]);
if (recs > 1)
apex.message.showErrors([
{
type: apex.message.TYPE.ERROR,
location: ["page"],
message: "Please Select just one Transaction",
unsafe: false
}
]);
if (recs == 1) {
$.each(records, function(i, r) {
trxID = gridView.model.getValue(r, "TRX_ID");
alert(trxID);
});
apex.server.process("manual_transmit", {
x01: trxID,
}, {
dataType: 'text'
}).done(function (pData) {
console.log(pData);
if(pData.success == "ERROR") showErrorMessage(pData.message)
if(pData.success == "OK") apex.navigation.redirect(pData.message);
});
};
-
Hi,
Can you create an example on apex.oracle.com please?
Cant debug here.
Thanks,