Oracle form builder trigger - oracle

I want add to my block text item where I display count of my all record:
code is:
BEGIN
GO_ITEM('KIEKKAT');
SELECT COUNT(*)
INTO :KATEGORIJA.KIEKKAT
FROM KATEGORIJA;
END;
This wordk only if I choose trigger "WHEN-MOUSE-CLICK" ,but then all other items not display data. If I choose other trigger all items not displaying anything. i want tat this text item will all time display count of record. Please say me, how to do it, whicj trigger set I do my code if correct ?

I would consider a Summary item for this purpose - especially if you already have a block based on the KATEGORIJA table.
You add an item which is based on a COUNT from that block: set Calculation Mode to Summary, Summary Function to Count, and set Summarized Block to the block. Set the Query All Records property on the block to True.

Try it on the POST-SELECT trigger at the block level.
From the documentation:
Description
The Post-Select trigger fires after the default selection phase of query processing, or after the successful execution of the On-Select trigger. It fires before any records are actually retrieved through fetch processing.
Usage Note:
Use the Post-Select trigger to perform an action based on the outcome of the Select phase of query processing such as an action based on the number of records that match the query criteria.
Edit.
take a look at this
https://forums.oracle.com/forums/thread.jspa?threadID=883340
You can get the number from a block property.

Related

Want to know how to populate data from One block to another?

I have two database Datablock
In the First Block I have a Item called parameter name with LOV. While selecting that LOV ,it should populate Next Item Also that is Section
Now What i want is when I am selecting the Parameter name LOV from First Data Block. I want to populate the corresponding data in the list Value of the Second Data Block
For this i used post text item -->Inside that I used go block But it throws illegal restriction Error
Now I am out of ideas
If I understood you correctly, you're talking about cascading LoVs. If that's so, then the 1st LoV query looks like this:
select parameter_name, section
from some_table
where some_condition;
You set it to populate appropriate fields in the 1st data block (one of them is :block_1.parameter_name).
The second block's LoV would then "reference" the first block's field:
select another_column
from another_table
where parameter_name = :block_1.parameter_name --> this
and other_conditions;
You don't need any triggers; once you display 2nd block field's list of values, it'll use that where clause and display only values that match the condition.

Can I use a list to repeat two tablixes on a report page?

See image below. Warehouse and Customer are dropdown lists populated via query. Year is a text field. The two tables display data from datasets driven by the report parameters. Is there a way to repeat the two tables based on each member of the Customer dropdown? Preferbly with a pagebreak after the 2nd table.
I normally do this using subreports. You could either create a single subreport that contains both tables or individual subreports. The individual approach might help with page breaks etc so that's the way I'd go.
Step 1: Create a report for your first table.
As you don't state what each table does, I'll make some up for the sake of illustration.
The key is to create a subreport that displays just the info you need in a single table. So in your case this might mean we only need to pass in a single parameter, CustomerID. You might need to pass in more such as Warehouse but I don't know...
In my made up scenario, let's assume the report shows customer contacts so we create a subreport (let's call it subCustomerConacts). It has a single parameter pCustomerID and a single dataset dsCustomerContacts. The query might looks something like SELECT * FROM CustomerContacts WHERE CustomerID = #pCustomerID. Add whatever tables/textbox etc you need to display your data.
Test this subreport works by manually typing in a CustomerID
Step 2: Create a report for your second table.
Do exactly the same again, creating a new subreport. Let call this subCustomerOrders. Repeat as above until you end up with another report that can display order details (or whatever you need).
Finally, create you main report.
This is basically what you have described in you question in terms of parameters etc.
Now to add this bit that will call you subreports.
Create a dataset (let's call it dsCustomerLoop) that contains each customer from your parameter something like SELECT DISTINCT CustomerID FROM myCustomers WHERE CustomerID IN (#myCustomerParameter)
Add a table to your report, 1 column wide and stretch it so it's wide enough to accommodate you subreports.
Set the dataset to point to dsCustomerLoop
Right-Click the cell in the detail row and do "Insert Row -> Inside Group - Below". You should not have two detail rows.
Next, right click the top detail row and do "Insert -> Subreport"
Right-Click the newly inserted subreport control and choose "properties".
Choose your first SubReport form the drop-down list
Click parameters on the left,
Click "Add" and select the CusomterID parmeter, set it's value to the CustomerID field.
Repeat this process on the seconds row, choosing your seconds subreport.
You may want to also add a 3rd row to the table, you could insert a rectangle into this with page breaks set to force a new page after each seconds subreport.
That's It. When the report runs it will produce two rows per customer, each row containing a subreport.
I hope this is clear enough, I've rushed through it a bit but if anything is unclear, let me know and I'll provide a clearer solution.

Oracle APEX | How to change select list value and Submit it dynamically

I have two select lists
1. The first one P4_country_id_B contains countries names
select country_name as d, country_id as r
from countries
2. The second one P4_CITY_ID_B contains cities of a country based on selected value in P4_CITY_ID_B.
select city_name as d, city_id as r
from cities
where country_id = :P4_country_id_B
Everything goes OK without any problem.
BUT
I use Execute PL/SQL Code Dynamic Action to change selected values of those lists like this (for example):
:P4_country_id_B:=country_returned_value;
:P4_CITY_ID_B:=city_returned_value;
Where
country_returned_value : is a one value of countries list values for example (USA)
city_returned_value : is a one value of cities list values for example (NewYourk).
The first selected list value changes but the second list never changes.
Notes:
I used P4_country_id_B,P4_CITY_ID_B as Page Items to Submit for the dynamic action.
I don't whan to submit the page instead of dynamic action
How can I change list values in this case please?.
Thanks in advance.
Cascading select lists are refreshed through ajax.
Change select list 1, select list 2 will be refreshed.
You execute plsql, which in turn will set the value of the items involved. Both are select lists, and one is dependent on the other.
So while both will be set, the change of the first one will cause the second to be refreshed.
In other words, you're doing it too fast. And while there is a solution, the proper way is a bit complex and I wouldn't build it in DA's personally.
You haven't specified how or when you call the code which sets the values for the items. So here I'll just assume a DA with an action of type "Execute JavaScript" (for example)
// perform a call to the ajax callback process to get the country and city id
// there are several ways to provide values to the process if necessary.
// for example through x01, which can be used in the proces like
// apex_application.g_x01
apex.server.process('GET_COUNTRY_DEFAULTS', {x01:""}).done(function(data){
// process returns JSON which contains 2 properties: country_id and city_id
// data.country_id
// data.city_id
// bind a ONE-TIME handler to the after refresh event of the city
// cascading LOVs fire the before and after refresh events like any other
// refreshable element in apex
// a one time handler since the values are different each time this code will
// execute
apex.jQuery("#Px_CITY_ID").one("apexafterrefresh",function(){
// after refresh of the list, attempt to set the value of the list to the
// value retrieved earlier
apex.item(this).setValue(data.city_id);
});
// finally, set the value of the country. Doing this will also trigger the
// refresh of dependent elements
apex.item('Px_CITY_ID').setValue(data.country_id);
// since a handler has been bound, the refresh will occur, the after refresh
// triggers, and the value will be set properly
});
Finally, create a new process on the page under "AJAX Callback", and name it GET_COUNTRY_DEFAULTS
DECLARE
l_country_id NUMBER;
l_city_id NUMBER;
BEGIN
l_country_id := 8;
l_city_id := 789;
htp.p('{"country_id":'||l_country_id||',"city_id":'||l_city_id||'}');
EXCEPTION WHEN OTHERS THEN
-- returning an error while using apex.server.process will prompt the user
-- with the error and halt further processing
htp.p('{"error":"'||sqlerrm||'"}');
END;
That should tie everything together.
I think there is some confusion here. My answer below, assumes, according to your question, the first list name is P4_country_id_B, and the second list name is Cities_LOV. If that is not the case, please clarify.
Your first list called P4_country_id_B, and you assign it to itself through the following statement:
:P4_country_id_B:=country_returned_value;
So basically, nothing has changed, the value of P4_country_id_B is the returned value of your list P4_country_id_B without any need for this assignment. Note, it is not clear to me, what is country_returned_value, because P4_country_id_B holds the returned value.
Secondly, you have a list called Cities_LOV, and you assign the returned value to P4_CITY_ID_B page item, through the following statement:
:P4_CITY_ID_B:=returned_city_value;
Again, I am not sure what is returned_city_value, because Cities_LOV holds the returned value of that list.
I am not sure what you are trying to achieve here. But I assume, you want to allow the user to select the Country first, and then based on that, you want to refresh the Cities list to display the cities in that particular country. If that is the case, then use a dynamic action on P4_country_id_B value change, to refresh the value of Cities_LOV. You only need to pass P4_country_id_B to that dynamic action.
UPDATE
After you corrected the wording of the question, the answer would be like this:
In your child list P4_CITY_ID_B make sure you set the option Cascading LOV parent item(s) to the parent list P4_country_id_B. You do not need the dynamic action. The child list, should refresh upon the change of the parent list. The answer here, goes in details about how to implement cascading list

Oracle Apex 5.0: Wait to generate IR until criteria fields entered

I have an APEX 5.0.3.00.03 page with dozens of criteria fields, followed by a region containing an Interactive Report (IR). I want to defer the IR being produced until a "Generate" button is clicked, but I am having troubles. The report without criteria would generate millions of rows, via a nasty 5 table join, so I want to defer it processing until the user is ready. I know that I can do a /*+ FIRST_ROWS */ hint, but still want to avoid invoking the SQL until the user picks some criteria.
I tried the following:
Created a Hidden Field P210_WAIT, initial value of 'TRUE', which I included in the SQL criteria like this:
select * from tab_1, tab_2, tab_3, tab_4, tab_5
where :P210_WAIT != 'TRUE'
and -- join, and dozens of other criteria here
and in a dynamic action on the Generate button, I do two things:
Execupte PL/SQL Code to set :P210_WAIT := 'FALSE';
Refresh Action:
Action: Refresh
Affected elements: Selection Type: Region. Region: (region containing my IR)
I have debug statements in the PL/SQL code, and they are appearing, but the SQL to produce the report is not being run, implying that the Refresh Action is not "waking up" the IR.
It does appear the IR SQL is being executed on page load, as I was dynamically setting the IR Attribute "When No Data Found" value to initially say "Please select criteria and click the Generate button to display report" and that was working.
If I understand your problem correctly, your main problem here would be: the dyanamic action to refresh the region is not working, am i correct?
If that is the problem, try this:
First, make sure that all the bind variables in the source query is listed on the Page Items to Submit under the source query region.
Then, Assign Static ID for the IR region.
Next will be, changing the Refresh dynamic action to Execute Javascript and paste this
$('#static_id').trigger('apexrefresh');
Hope this helps.

Clearing one block before entering query mode in another

Before I ask my question, I have to say that the database that I'm working on doesn't have foreign keys, so I can't make master-detail blocks, and because of that I'm using workaround with go_block, clear_block, execute_query and triggers.
I have a form with two blocks. If we presume that the both blocks are filled with info, and that I want to execute query on first one, is there a way to clear the other block before entering query mode?
e.g.
Block1: ID, NAME, SURNAME
Block2: INFO1, INFO2, ..., Id_block1 etc.
So, if there is info on both blocks, and I enter the query mode on Block1, whole block clears so I can enter search criteria, but the second block still has the data from the last executed query. Is there a way to clear the data on the second block as well? Once again, I want to clear the data from Block2 when I'm IN ENTER-QUERY MODE on Block1.
Workflow: Enter-query mode Block1, execute-query Block1, NEW-RECORD-INSTANCE trigger activates (where workflow continues), go_block('Block2'), execute_query on Block2 (with where clause Id_block1 = block1.id).
I'm using Oracle Forms 10g. I appreciate any help you can provide.
It is possible to create the MASTER-DETAIL relationship while creating one of the blocks in your form
or
you can just write the following on the KEY-ENTQRY trigger :
go_block('block2');
clear_block;
go_block('block1');
enter_query;
After this, the block1 will be in the enter-query mode and you can search the data and just execute the block.

Resources