Oracle Apex Add IF Statement to set a value in a form - oracle

I am working on a system in Oracle Apex 22.1 where there is a Form, where the user enters an amount of money to be validated by the company. There are 3 fields which are a select list P3_REQUEST_TYPE, a text field P3_AMOUNT and a select list P3_TYPE_CURRENCY. What I want to do is that if the user selects the option "Payment Request" in P3_REQUEST_TYPE, and according to the amount entered in P3_AMOUNT and the type of currency in P3_TYPE_CURRENCY (USD, JPY), put the value "1" in the field P3_FG_RT for validation reasons.
I would like to know if there is a way to do it through a IF function since through dynamic actions I have not been able to make it work, I would greatly appreciate your help.
The amounts for the "1" to be placed are: if it is greater than or equal to 5,000 and they are USD, or if it is greater than or equal to 18,000 and they are JPY.

That looks like dynamic action, indeed.
its action would be "Set value"
type might be PL/SQL Function body:
RETURN CASE WHEN :P3_REQUEST_TYPE = 'Payment Request'
AND :P3_TYPE_CURRENCY IN ('USD', 'JPY')
THEN 1
END;
items to submit: P3_REQUEST_TYPE, P3_TYPE_CURRENCY
affected elements: item, P3_FG_RT
Though, as you said that these are Select List items, I kind of doubt that return values really are "Payment Request" or "JPY" - I presume that you actually return their codes, not descriptions so CASE expression might need to be changed.

The decision to use a dynamic action depends on the following question: is the value that needs to be set of importance before the page is submitted or does it only matter at submit time
#Littefoot explained how to do the dynamic action but if this value is only needed after the page is submitted, it is easier to set the value of page item P3_FG_RT with a a computation (process point After Submit).
One way to implement this computation is:
Type: Static Value
Static Value: 1
Server Side Condition: Expression
PL/SQL Expression:
:P3_REQUEST_TYPE = 'Payment Request' AND :P3_TYPE_CURRENCY IN ('USD', 'JPY')

Related

How to Select multiple related columns in add calculated fields in Quicksight parameter using ifelse?

I have a parameter 'type' in a table and it can have multiple values as follows -
human
chimpanzee
orangutan
I have 3 columns related to each type in the table -
human_avg_height, human_avg_weight, human_avg_lifespan
chimpanzee_avg_height, chimpanzee_avg_weight, chimpanzee_avg_lifespan
orangutan_avg_height, orangutan_avg_weight, orangutan_avg_lifespan
So if i select the type as human, the quicksight dashboard should only display the three columns -
human_avg_height, human_avg_weight, human_avg_lifespan
and should not display the following columns -
chimpanzee_avg_height, chimpanzee_avg_weight, chimpanzee_avg_lifespan
orangutan_avg_height, orangutan_avg_weight, orangutan_avg_lifespan
I created the parameter type and in the add calculated fields I am trying to use ifelse to select the columns based on the parameter selected as follows -
ifelse(${type}='human',{human_avg_height}, {human_avg_weight}, {human_avg_lifespan},{function})
I also tried -
ifelse(${type}='human',{{human_avg_height}, {human_avg_weight}, {human_avg_lifespan},{function}})
And -
ifelse(${type}='human',{human_avg_height, human_avg_weight, human_avg_lifespan},{function}})
But none of it is working. What am i doing wrong ?
One way to do this would be to use three different calculated fields, one for all the heights, one for weights and one for lifespan. The heights one would look like this:
ifelse(
${type}='human',{human_avg_height}, ifelse(
${type}='chimpanzee', { chimpanzee_avg_height}, ifelse(
${type}='orangutan',{ orangutan_avg_height},
NULL
)))
Make another calculated field for weights and lifespan and then add these calculated fields to your table, and filter by type.
To make it clear to the viewer what data is present, edit the Title of the visual to include the type:
${type} Data
You have to create one calculated field for each measure using the ifelse with the type to choose the correct vale, but is not necessary to create inner ifelse as skabo did, the if else syntax is ifelse(if, then [, if, then ...], else) so you can define the calculated fields as follows:
avg_height = ifelse(${type}='human', {human_avg_height}, ${type}='chimpanzee', {chimpanzee_avg_height},${type}='orangutan', {orangutan_avg_height}, NULL)
avg_weight = ifelse(${type}='human', {human_avg_weight}, ${type}='chimpanzee', {chimpanzee_avg_weight},${type}='orangutan', {orangutan_avg_weight}, NULL)
avg_lifespan = ifelse(${type}='human', {human_avg_lifespan}, ${type}='chimpanzee', {chimpanzee_avg_lifespan},${type}='orangutan', {orangutan_avg_lifespan}, NULL)
Then use those calculated fields in your visuals.

Oracle Apex 4.2 Tabular Form checkbox for changed column value

I have an Apex Tabular form:
ID Name Title Class ROW_EDIT <br>
1 Smith Mgr AP (checkbox)<br>
etc...
I am trying to activate the 'checkbox' ROW_EDIT column - which has a default value of Y - when the user changes the value for the tabular form column Class (Select list) in the same row. I can change the ROW_EDIT attribute to text (ie, Y) if easier...
I have no apex_items for the page to reference - all columns are tabular form.
I have researched some dynamic change events - but I can't seem to get the row-reference to set correctly.
Any help would be greatly appreciated.
Thanks
Unfortunately, last time I saw APEX 4.2 was 2 years ago and I don't have it now.
The idea is in the following:
Add onchange event to select list. I don't remember is there an easy way to do this. If not, you can create a select list manually using APEX_ITEM package. To do this, write in the source query:
select apex_item.select_list_from_lov (
p_idx => 10,
p_value => class, -- it is a name of a table column
p_lov => 'my_lov_name',
p_attributes => 'onchange="my_func.call(this);"')
from ...
In page properites (JavaScript section), create a javascript function:
function my_func () {
this.parentElement.parentElement.getElementsByTagName("input")[0].checked = true;
}
Parameter this in the function is a reference to select list. Hence, this.parentElement.parentElement - reference to row with the triggering select list, getElementsByTagName("input")[0] is a checkbox. If you have several input elements in the row, use proper index instead of 0.
How this JavaScript code works you can check here: https://codepen.io/anon/pen/NvPmPp

Calculated control displays the total number of records that appear in the subform

My assignment is to create a calculated control that displays to total number of Members in the subform. How can I accomplish this when there is no definitive field that I can use in the expression. There are only three fields in the subform: First Name, Last Name, and Phone. If I do something like this =[frmPlanMemberSubform].[Form]![FirstName] that only calculate and displays the first name of the member in the subform. Actually there are only two names in the subform. Theoretically I suppose to get back a count of 2. But I can't figure out how to do it with the existing fields in the subform. Any Access experts out there? Please help. Here is what the database looks like in form view.
As you can see there is nothing in the Total Members control box.
Follow these steps:
1) In the code of the master form insert a function similar to this:
Private Function NumRecords()
Dim rec As Recordset
On Error GoTo lbErr
Set rec = Me!<subform-name>.Form.RecordsetClone
rec.MoveLast
NumRecords = rec.RecordCount
lbExit:
Exit Function
lbErr:
MsgBox Error, vbExclamation
Resume lbExit
End Function
2) In the field to display the number of records insert the following string in the value property:
=NumRecords()
3) Create the Form_Current trigger as follows:
Private Sub Form_Current()
Me!<fieldname>.Requery
End Sub
enter image description here

Check if input field is empty or not

I have 10 textboxes x 3 so about 30.
Name - Age - SEx
so 10 persons in all.
I have this current code:
if(array_key_exists('submit',$_POST)){ //CHECKS IF FORM WAS SUBMITTED, ELSE LOADS TO VIEW
for($counter=1;$counter<11;$counter++){ //I LOOPED THE 10 FIELDS, STARTING FROM 1, 1-10
if($_POST['ingredient'.$counter]!=null){ // CHECK IF ATLEAST NAME IS NOT EMPTY, IF EMPTY EVEN IF THE OTHER 2 INPUTS ARE NOT I WILL NOT INCLUDE IT.
$this->form_validation->set_rules('Name'.$counter,'Name #'.$counter,'trim');
$this->form_validation->set_rules('Age'.$counter,'Age of'.$_POST['name'.$counter],'trim|required|numeric');
$this->form_validation->set_rules('Sex'.$counter,'Gender of'.$_POST['name'.$counter],'trim|required');
}
Im only adding required on the other 2 fields since name shouldnt be null to be inside the if(success){ } clause
Is there any other better way?
CALLBACK QUESTIONS.
When using form_validation, say i used a callback function. how would i be able to print the necessary error_message for that callback since ci wont be able to know what that function was all about.

how to code the itemchanged event and datawindows

I am using PowerBuilder classic 12.5
am having difficulties in inserting, editing, creating and printing reports.
i have a datawindow, dw_NewEmployee with dataobject, d_newrecord which is update-able.
should i use the columns to insert records through the columns or i
create single line texts on the window object
is the itemchanged event used on columns and rows on dataobject or
on single line texts... I am having trouble figuring out how to implement validation rules.
please give me an example to validate employee ID_Number
I see that you seem confused about the datawindow usage.
Let's try to summarize:
you create a new datawindow d_newrecord (say it is a grid) based on a sql select in your database, say select id_number, name from employee.
in the detail zone of the datawindow (that will be repeated for each record at runtime but that is only once in design), you need to put one column object for each column (here you will have id_number and name) these objects are both to display existing data and receive user input for editing data and inserting new records.
don't forget to set the Rows / Update properties if you need to make the dw updatable.
in the header zone of the datawindow you can have a static text associated to each column that is just here to display the column name, it does not concern table data.
in some window object, you place a datawindow control dw_newemployee where the content of the datawindow will be painted, you set d_newrecord as its dataobject.
you need to set at some point the transaction object of the dw, for example in the open() event of the window:
dw_newemployee.SetTransObject(sqlca)
dw_newemployee.Retreive() //if you are using some retreival arguments, don't forget to include them here
When you want to insert new data in your table (for example with a window button "add"), in the clicked() event of the button you call dw_newemployee.InsertRow(0) to insert at the end.
The ItemChanged() event will be triggered after one cell will be modified, you will be given the row, item (a dwobject) and new data. By choosing the returned value of the event, you can accept or reject the new data.
Here is an example for a field validation in itemchanged() event:
long ll_return_code = 0
string ls_column
ls_column = lower(dwo.name)
choose case ls_column
case "id_number"
if long(data) = 42 THEN
messagebox("validation error", "You cannot use 42 for the ID")
ll_return_code = 1 //reject and stay in cell
end if
case "name"
if data = "foobar" then
messagebox("validation error", "Do not use dummy value...")
ll_return_code = 2 //reject but allow to go elsewhere
end if
end choose
return ll_return_code

Resources