Set select list value via PLSQL - oracle

I am calling an apex page via URL and pass all item values in the request like
f?p=&APP_ID.:44:&SESSION.:INSERT:&DEBUG.:44:P44_NAME,P44_DESCRIPTION,P44_PARENT_PK_ID:#NAME#,#DESCRIPTION#,#PARENT_PK_ID#_#PK_ID#
In my case I have to check if the row has a parent key reference value. If yes I have to set the parent key reference value to P44_PARENT_PK_ID. Otherwise, I have to set the key reference value (#PK_ID#) to P44_PARENT_PK_ID. That's why I am passing both values split with "_" in the URL.
On page 44 I have a process on the "Before Regions" process point:
DECLARE
v_demilitedstring varchar2(100);
BEGIN
v_demilitedstring := v('P44_PARENT_PK_ID');
IF nvl(to_number(substr(v_demilitedstring, 1, instr(v_demilitedstring, '_', 1, 1) -1)), 0) = 0 then
:P44_PARENT_PK_ID := substr(v_demilitedstring, instr(v_demilitedstring, '_', -1, 1) +1);
ELSE
:P44_PARENT_PK_ID := substr(v_demilitedstring, 1, instr(v_demilitedstring, '_', 1, 1) -1);
end if;
END;
I set the success message as &P44_PARENT_PK_ID. to check if the right value is assigned to it. The procedure is working fine and the correct value is set to P44_PARENT_PK_ID. However, the assigned value is not selected in select list (Meaning the display name of value is not displayed).
How can I trigger the select list item to change it's display value?

So it sounds like you have a select list generating correctly and you you want to change the value that is selected when the page loads. For that, go to the Source section of the select list item. You can drive that based on another page item, like P44_PARENT_PK_ID, a query, or a number of other options.
Make sure that the list of values for your select list will have the source value in it.

Related

Disable a button when certain condition is matched

I have two items P1_ENDTIME,P1_CURRENTDATE. The first item(P1_ENDTIME)has value which i am getting from interactive grid column. And in second item(P1_CURRENTDATE) is having current date.
I want to disable the button when current date(P1_CURRENTDATE) value is higher than end time (P1_ENDTIME).
Create a new page item P1_ISFUTURE
Create a dynamic action on change of P1_CURRENTDATE
Add a true action of type "Execute Server-side Code"
PL/Sql Code:
IF TO_DATE(:P1_ENDTIME,'DD-MON-YY') > TO_DATE(:P1_CURRENTDATE,'DD-MON-YY') THEN
:P1_ISFUTURE := 'Y';
END IF;
Items to submit: P1_ENDTIME, P1_CURRENTDATE
Items to return: P1_ISFUTURE
Add a true action of type "Disable" for the button with client-side condition of type "Item = Value" and values P1_ISFUTURE, Y
Add a true action of type "Enable" for the button with client-side condition of type "Item != Value" and values P1_ISFUTURE, Y
Side Note: You don't need to store the current date in P1_CURRENTDATE. Instead you could just use
IF TO_DATE(:P1_ENDTIME,'DD-MON-YY') > SYSDATE THEN
:P1_ISFUTURE := 'Y';
END IF;

how I can control text of selected item in list item in oracle forms?

I am a beginner in PL/SQL and Oracle Forms .
I am working in an Oracle form. Created a push button and updated it to item type: list item. I want to choose between items when I click on it. I should redirect with if according to the item chose. How can I do that?
NOTE: I'am using forms 6i ,
item_type : list item
list style : popup list
elements in list : S_SATIS(value : item24) - S_MARKA(value : item25)
trigger : when-list-changed
This is how I got list item name and values:
l_count := GET_LIST_ELEMENT_COUNT('list_item');
FOR i in 1..l_count LOOP
IF GET_LIST_ELEMENT_VALUE('list-item',i) = :list_item THEN
l_text := GET_LIST_ELEMENT_LABEL('list_item',i);
l_value := Name_In('list_item');
I want to redirect according to the item selected with if. This is the method I think is correct. But it is not working correctly. I used message to see if it goes inside the if . but it didn't print the message. How can I fix?
ELSIF l_value = '<list item value name>' THEN
message(l_value);
GO_BLOCK('<block_name>');
EXECUTE_QUERY
ELSIF l_text = '<list item name>' THEN
message(l_text );
GO_BLOCK('<block_name>');
EXECUTE_QUERY
this way the problem is solved

APEX Office print

I am currently working with the Apex Office Print it would be nice if you could help me with two points.
I am creating a template with a lot of fields, and around 50% of
these fields are optional, so they are often only (null) in my
database. Can I do something so that the fields with no value are not
shown?
My second question would be the work with the print function and
checkboxes. How do I integrate the item APEX_APPLICATION.G_F01 so
that I only print the content of a selected checkbox ? It is not
really working in the PL/SQL section.
I am creating a template with a lot of fields, and around 50% of these fields are optional, so they are often only (null) in my database. Can I do something so that the fields with no value are not shown?
The {tag} will just be removed when it's empty. In case you want to make some blocks disappear you can wrap that in a condition,
for example:
{#tags=null} {product_name}: {product_description} {/tags=null} {#tags!=null} {product_name}: {tags} {/tags!=null}
or if you have a value:
{#checked=="Yes"}☒Yes ☐No{/checked=="Yes"}{#checked!="Yes"} ☐Yes ☒No {/checked!="Yes"}
My second question would be the work with the print function and checkboxes. How do I integrate the item APEX_APPLICATION.G_F01 so that I only print the content of a selected checkbox ? It is not really working in the PL/SQL section.
Are you running the AOP Process type plugin or the Dynamic Action plugin?
For example we use it for ourself when selecting invoices and printing them.
We have a checkbox in an IR:
apex_item.checkbox2(
p_idx => 1,
p_value => id,
p_attributes => 'class="invoice_id"',
p_checked_values => :P39_INVOICE_ID_LIST,
p_checked_values_delimiter => ',') as chk,
And then we have a Dynamic Action on change that sets an hidden item (P39_INVOICE_ID_LIST) on the page:
var
//Checkbox that was changed
$checkBox = $(this.triggeringElement),
//DOM object for APEX Item that holds list.
apexItemIDList = apex.item(this.affectedElements.get(0)),
//Convert comma list into an array or blank array
//Note: Not sure about the "?" syntax see: http://www.talkapex.com/2009/07/javascript-if-else.html
ids = apexItemIDList.getValue().length === 0 ? [] : apexItemIDList.getValue().split(','),
//Index of current ID. If it's not in array, value will be -1
idIndex = ids.indexOf($checkBox.val())
;
//If box is checked and it doesn't already exist in list
if ($checkBox.is(':checked') && idIndex < 0) {
ids.push($checkBox.val());
}
//If box is unchecked and it exists in list
else if (!$checkBox.is(':checked') && idIndex >= 0){
ids.splice(idIndex, 1);
}
//Convert array back to comma delimited list
apexItemIDList.setValue(ids.join(','));
In our query in the AOP DA we have:
where i.id in (select regexp_substr(:P39_INVOICE_ID_LIST,'[^,]+', 1, level) invoice_id
from dual
connect by regexp_substr(:P39_INVOICE_ID_LIST, '[^,]+', 1, level) is not null)
and we make sure the P39_INVOICE_ID_LIST is set in session state by specifying the Affected Elements of the AOP plugin call.
If you setup an example of what you want to do on apex.oracle.com I'm happy to build you the example there. In AOP 4.0 we will also include an example with checkboxes.
Hope that helps,
Dimitri

Get current cell value in DBGrid

In my Delphi application, I use lookup fields, but in unusual way. Actually, I wanna update field in underlying data set, just like if it was in the same table.
Existing guides tell that there is no problem, just join the table and voila... I envy if they really succeeded this task with such simple solution. I do not. BTW I think I'm getting close to reach my goal. I have one question left: how the hell I can get value I just entered into DBGrid Cell?
I tried DBGrid[FieldName].EditValue and .DisplayText, but they show the same value as Field.Value, which doesn't change after exiting the column, because it is lookup field. Sender.NewValue is null. I'm using this function to update lookup table:
procedure TKDGridForm.LookupFieldChange(Sender: TField);
begin
if not Assigned(Sender) then
Exit;
Sender.OnChange := nil;
if not Assigned(Sender.LookupDataSet) then
Exit;
if Sender.LookupDataSet.Locate(Sender.LookupKeyFields, Sender.DataSet[Sender.KeyFields], []) then
Sender.LookupDataSet.Edit
else
Sender.LookupDataSet.Append;
// how do I get the value I just entered?
Sender.Value := KDGrid3[Sender.FieldName].DisplayText;
Sender.LookupDataSet.FieldValues[Sender.LookupResultField] := Sender.Value;
Sender.LookupDataSet.Post;
Sender.OnChange := LookupFieldChange;
end;
Here is SQL I used before I ended up with lookup fields:
select det.*,
od1.T_EQ T_SHABLON_EQ,
od1.T_NV T_SHABLON_NV,
od1.T_PRIM T_SHABLON_PRIM,
od2.T_EQ T_PRAVKA_EQ,
od2.T_NV T_PRAVKA_NV,
od2.T_PRIM T_PRAVKA_PRIM,
od3.T_EQ T_VALCOV_EQ,
od3.T_NV T_VALCOV_NV,
od3.T_PRIM T_VALCOV_PRIM,
od4.T_EQ T_REZKA2_EQ,
od4.T_NV T_REZKA2_NV,
od4.T_PRIM T_REZKA2_PRIM
from CMKNEW.details det
left join CMKNEW.OperDetails od1
ON det.nrec = od1.cdetail
and 81 = od1.coper
left join CMKNEW.OperDetails od2
ON det.nrec = od2.cdetail
and 82 = od2.coper
left join CMKNEW.OperDetails od3
ON det.nrec = od3.cdetail
and 83 = od3.coper
left join CMKNEW.OperDetails od4
ON det.nrec = od4.cdetail
and 84 = od4.coper
where det.ckd=:CKD order by det.NREC
Hope it will explain my task clearer. If you wanna mcve, I can extend this, though I think it's not essential.
My database is Oracle, connected through ADO. I'd like the solution to be as simple as possible.
I assume you're talking about a standard TDBGrid and that what you're asking is how to get the text which is displayed in a cell of the grid when you type into it, but before the grid's dataset is updated. At that point, the current row indicator in the LH column will have changed from the default right-pointing triangle to an I-beam
If so, the snippet below shows you how to do get this text value. The point is, in the condition I've described, what's in the cell hasn't yet been posted back to the underlying dataset field. What happens is that when you start editing, an InplaceEditor (TCustomMaskEdit descendant) is dynamically created, and it's this which holds the text value which is being edited.
Add a TTimer and a TMemo to your form and then run the code below to see what I mean.
type
TMyGrid = Class(TDBGrid);
procedure TMyForm.Timer1Timer(Sender: TObject);
var
S : String;
Grid : TmyGrid;
begin
Grid := TmyGrid(DBGrid1);
if Grid.InplaceEditor <> Nil then
S := Grid.InplaceEditor.Text
else
S := IntToStr(Grid.Col) + ':' + IntToStr(Grid.Row);
Grid.Invalidate;
Memo1.Lines.Insert(0, S);
end;

FastReport Master/Detail in Delphi XE2

I need some help creating a Master/Detail report in Fast Reports for Delphi XE2.
I have a simple form which accepts 2 dates and 2 times from a user. I then have 2 Oracle Datasets on the form with which to retrieve my data. When the user presses the print button, the program accepts the values from the user and sends the values to the first oracle dataset, which then in turn retrieves the first value, and then sends this value along with the user accepted values to the second dataset to print the detail pertaining to the value retrieved.
For each dataset I do have a corresponding frxDBDataset component which is then assigned to the frxReport1 component. With in the report, I have created a Master Band which is assigned to dataset1, and a Detail Band assigned to datset2. When I run my report, dataset 1 brings back all the records, but dataset 2 only brings back the records for the first value and duplicates it for every record in dataset1.
Below is the code I am trying to execute:
opr_operator_ods.Close;
opr_operator_ods.SetVariable('DATEFROM', opr_datefrom_dtp.Date);
opr_operator_ods.SetVariable('DATETO', opr_dateto_dtp.Date);
opr_operator_ods.SetVariable('TIMEFROM', opr_timefrom_dtp.Text);
opr_operator_ods.SetVariable('TIMETO', opr_timeto_dtp.Text);
opr_operator_ods.Open;
if opr_operator_ods.RecordCount > 0 then
begin
while not opr_operator_ods.Eof do
begin
opr_operatorcount_ods.Close;
opr_operatorcount_ods.SetVariable('DATEFROM', opr_datefrom_dtp.Date);
opr_operatorcount_ods.SetVariable('DATETO', opr_dateto_dtp.Date);
opr_operatorcount_ods.SetVariable('TIMEFROM', opr_timefrom_dtp.Text);
opr_operatorcount_ods.SetVariable('TIMETO', opr_timeto_dtp.Text);
opr_operatorcount_ods.SetVariable('OPERATOR',
opr_operator_ods.FieldByName('opr_code').AsString);
opr_operatorcount_ods.Open;
while not opr_operatorcount_ods.Eof do
begin
frxReport1.PrepareReport(false);
opr_operatorcount_ods.Next;
end;
frxReport1.PrepareReport(true);
opr_operator_ods.Next;
end;
DecodeDate(opr_datefrom_dtp.Date, tyear, tmonth, tday);
StartDate := '''' + IntToStr(tday) + '/' + IntToStr(tmonth) + '/' + IntToStr(tyear) + '''';
DecodeDate(opr_dateto_dtp.Date, tyear, tmonth, tday);
EndDate := '''' + IntToStr(tday) + '/' + IntToStr(tmonth) + '/' + IntToStr(tyear) + '''';
frxReport1.Variables['StartDate'] := StartDate;
frxReport1.Variables['EndDate'] := EndDate;
//frxReport1.PrepareReport(True);
frxReport1.ShowPreparedReport;
How do I get the second dataset to move on to the next record's values?
This report used to work perfectly in Delphi 2005 with RaveReports6, but there we used code based form development which was easier to manipulate with a 'writeln' and not visual like with Fast Reports.
When creating the preview FastReport does something like this code:
while not MasterBand.DataSet.Eof do
begin
...Do special FastReport's work :)
while not DetailBand.DataSet.eof do
begin
...Do special FastReport's work :)
DetailBand.DataSet.Next;
end;
MasterBand.DataSet.Next;
end;
In your code:
while not opr_operatorcount_ods.Eof do
begin
frxReport1.PrepareReport(false);
opr_operatorcount_ods.Next; <-- here opr_operatorcount_ods is in the last position from PrepareReport
end;
Data bands may be a master or detail type, but they only control the positioning of data of the output page
(order and number of times displayed).
Data displayed by the objects in the bands depends on relationship between the two (or more) datasets.
So you should made relation
Relationship can be done in several ways.
If you want to use parameters you can do this as follows:
Place DataSource component.
Connect it to dataset1(opr_operator_ods) using DataSet property DataSet = opr_operator_ods;
in DataSource.OnDataChange event write :
opr_operatorcount_ods.Close;
......
//Set parameter(relation between opr_operator(Master) and opr_operatorcount(Detail)
opr_operatorcount_ods.Params.ParamByName('opr_code').asString := opr_operator_ods.FieldByName('opr_code').AsString);
opr_operatorcount_ods.Open;
And then prepare and print report as:
procedure Print;
begin
//Prepare Master dataset ( parameters, close open etc.) like :
opr_operator_ods.Close;
opr_operator_ods.SetVariable('DATEFROM', opr_datefrom_dtp.Date);
opr_operator_ods.SetVariable('DATETO', opr_dateto_dtp.Date);
opr_operator_ods.SetVariable('TIMEFROM', opr_timefrom_dtp.Text);
opr_operator_ods.SetVariable('TIMETO', opr_timeto_dtp.Text);
opr_operator_ods.Open;
...
frxReport1.PrepareReport;
frxReport1.ShowPreparedReport;
end;

Resources