Oracle Apex referencing User Groups - oracle-apex

I am trying to build an application that will be used across 6 work sites. I would like to have all staff details lodged in the same application and each staff member will have a 'Site' assigned to them (the city in which they work). When a manager from that site uses the application I would like them to only see staff in the site that they have access to.
I have been struggling with this for a while.
I have set up all the tables and pages so that all staff can be seen.
I have created user groups and assigned different users to different groups (sites). I dont know how to limit the access or even reference the group that a user is assigned to.
Any help on this topic would be greatly appreciated.
Thank you in advance

I have found a suitable solution myself. I have created a Table called 'Tbl_000_UserAccess'
In this table there are 3 columns (ID, USER ID, Site ID).
I add the user and the site ID that they can view into this table.
Then I create a view on the staff table the restricts the records to the UserID of current User. Here is my view coding for anybody that is interested:
CREATE OR REPLACE FORCE VIEW "Vw_010_Staff" ("ID", "Emp No.", "First Name", "Last Name", "Team Leader", "Coach", "JE", "CD", "IRE", "FAM", "GB", "GST", "Emp", "SLS", "Bus RADC", "KS Ind", "KS N Ind", "Anon", "OB", "Resigned", "Reason", "Site") AS
select "Tbl_010_Staff"."ID" as "ID",
"Tbl_010_Staff"."Employee Number" as "Emp No.",
"Tbl_010_Staff"."First Name" as "First Name",
"Tbl_010_Staff"."Last Name" as "Last Name",
"Tbl_011_TeamLeaders"."First Name" || ' ' || "Tbl_011_TeamLeaders"."Last Name" as "Team Leader",
"Tbl_012_Coaches"."First Name" || ' ' || "Tbl_012_Coaches"."Last Name" as "Coach",
"Tbl_014_JE"."JE" as "JE",
"Tbl_010_Staff"."Customer Details" as "CDstuff",
"Tbl_010_Staff"."IR Essentials" as "IRE",
"Tbl_010_Staff"."Family Tax Credits" as "FAM",
"Tbl_010_Staff"."General Business" as "GB",
"Tbl_010_Staff"."GST" as "GST",
"Tbl_010_Staff"."Employers" as "Emp",
"Tbl_010_Staff"."Student Loans" as "SLS",
"Tbl_010_Staff"."Business Receivables" as "Bus RADC",
"Tbl_010_Staff"."Kiwi Saver Ind" as "KS Ind",
"Tbl_010_Staff"."Kiwi Saver NonInd" as "KS N Ind",
"Tbl_010_Staff"."Anonymous" as "Anon",
"Tbl_010_Staff"."Outbound" as "OB",
"Tbl_010_Staff"."Inactive" as "Resigned",
"Tbl_010_Staff"."Inactive Reason" as "Reason",
"Tbl_010_Staff"."Site" as "Site"
from (((("Tbl_010_Staff" left outer join "Tbl_011_TeamLeaders" on "Tbl_010_Staff"."Team Leader" = "Tbl_011_TeamLeaders"."ID")
left outer join "Tbl_012_Coaches" on "Tbl_010_Staff"."Coach" = "Tbl_012_Coaches"."ID")
left outer join "Tbl_014_JE" on "Tbl_010_Staff"."JE" = "Tbl_014_JE"."ID")
left outer join "Tbl_000_UserAccess" on "Tbl_010_Staff"."Site" = "Tbl_000_UserAccess"."SiteID")
**where "Tbl_000_UserAccess"."SiteID" =
(Select "Tbl_000_UserAccess"."SiteID"
from "Tbl_000_UserAccess"
where "Tbl_000_UserAccess"."UserID" = NVL(v('APP_USER'),USER))**
This has worked perfectly. the only annoyance is that when a user is added to the schema, I will also need to add a record to the useraccess table.
Please be aware that the UserID is case sensative
Hope this helps

Related

How to display and update the records I have added/insert in the Apex interactive report

I've created an interactive report to add/update/delete employee info records in custom db table.
My end user requirement is upon entering the employee number in the EMPNO field, all the details from the oracle standard table such as employee name, marital status, gender, bday must be auto generated in the form and they will only manually input the location name and mode of exit.
Now I created 3 pages: 1.home page, 2.add page, 3.update page
On page 1 (home page)
I have here the select SQL
with checkbox
On page 2 (add page),
In the page processing portion
I have
EventAddRecord
Source: db , plsql code
Here's my sample code:
BEGIN
INSERT INTO EMPINFOTBL
(PERSON_ID,
EMPLOYEE_NUM,
EMPLOYEE_NAME,
MARITAL_STATUS,
BDATE,
GENDER,
LOCATION_NAME,
MODE_OF_EXIT
)
VALUES
(SELECT PERSON_ID FROM
PER_PEOPLE_X WHERE EMPLOYEE_NUM = :P2_EMPLOYEE_NUM),
(SELECT EMPLOYEE_NUMBER ID FROM
PER_PEOPLE_X WHERE EMPLOYEE_NUM = :P2_EMPLOYEE_NUM),
(SELECT FULL_NAME FROM
PER_PEOPLE WHERE EMPLOYEE_NUM = :P2_EMPLOYEE_NUM),
(SELECT MARITAL_STATUS FROM
PER_PEOPLE WHERE EMPLOYEE_NUM = :P2_EMPLOYEE_NUM),
(SELECT DATE_OF_BIRTH FROM
PER_PEOPLE WHERE EMPLOYEE_NUM = :P2_EMPLOYEE_NUM),
(SELECT GENDER FROM
PER_PEOPLE WHERE EMPLOYEE_NUM = :P2_EMPLOYEE_NUM),
:P2_LOCATION_NAME,
:P2_MODE_OF_EXIT
);
END;
Buttons
SAVE with dynamic action
When click add button if True submit page
Now my problem is how to do the update when I click the check box,
I want my record to be displayed in the form because currently when I click the check box the form is null
To create a new record (using Page 2), you'd create a select list item which is based on per_people table; you'd display any information you want, but you'd return employee ID:
select full_name as display_value,
employee_num as return value
from per_people
order by full_name;
After selecting desired person, enter values into P2_LOCATION_NAME and P2_MODE_OF_EXIT items. When you hit the "Save" button (which submits the page), run the process (I modified what you wrote; should be way simpler):
INSERT INTO empinfotbl (person_id,
employee_num,
employee_name,
marital_status,
bdate,
gender,
location_name,
mode_of_exit)
SELECT person_id,
employee_number,
full_name,
marital_status,
date_of_birth,
gender,
:P2_LOCATION_NAME,
:P2_MODE_OF_EXIT
FROM per_people
WHERE employee_num = :P2_EMPLOYEE_NUM;
As of updating existing values: I'd again suggest you to use the Wizard as it creates everything you need - form page is based on empinfotbl table, while "Edit" button in Interactive report sends the ID value to form page whose pre-rendering process fetches data related to employee identified by passed ID.
If you created your own page, you'll have to do it all yourself.
You said:
I want my record to be displayed in the form because currently when I click the check box the form is null
Form items are empty because Apex didn't know what to fetch. As I said: pass ID value, create pre-rendering process. Or start over with the Wizard (I prefer that option).
#Littlefoot has given a perfect answer already, here are just some extra steps that might guide you to a solution (it's the "or start over with the wizzard" piece from Littlefoot's answer). I'd suggest looking how apex generates its pages when you do it out of the box. Just for testing, follow these steps
Create a new page of type "Interactive Report" and make sure to check the "Include Form Page" attribute
Give the form page a name and select "PER_PEOPLE" as table/view name
In the 2nd page of the dialog, select the primary key column of PER_PEOPLE: person_id
Click "Create Page"
You now have a working form and report that you can further customize to your specific requirements. It should give you a good idea of how a form and a report is generally configured in APEX and it saves you a ton of time
Notices how in the report page:
The edit link has the form page as target and passes the id
The CREATE button has the form page as target without the id
In the form page
No custom code is needed to initialize the form data for the current record. Instead the native process of type "Form - Initialization" is used.
No dynamic actions are used to perform the inserts - for a form that is a bad practice. Avoid it.
No custom code is needed to perform the inserts or update. Instead the native process of type "Form - Automatic Row Processing" is used.
Study these pages and apply similar logic to your own pages. It'll be a better app.

Creating Dynamic LOVs

I have a form in oracle apex with more than seven items on it. they are
SUBJECT_ID,GRADE_ID,DOMAIN_ID, CATEGORY_ID, STANDARD_CODE, STANADARD_STATEMENT, LEARNING_TARGETS.
I want these items SUBJECT_ID,GRADE_ID,DOMAIN_ID, CATEGORY_ID, STANDARD_CODE type to be select list. additionally, I want to make LOVs for each of these items.
LOV for SUBJECT_ID: I am making this LOV using a table SUBJECTS having TWO columns. MY query is SELECT SUBJECT_ID, SUBJECT_NAME FROM SUBJECTS It's working fine.
LOV for GRADE_ID: I am making this LOV using a table GRADES having TWO columns. MY query is SELECT GRADE_ID, GRADE_NAME FROM GRADES It's working fine.
LOV for DOMAIN_ID: I am making this LOV using a table DOMAIN having TRHEE columns. MY query is SELECT DOMAIN_ID, DOMAIN_NAME FROM DOMAIN WHERE SUBJECT=:P48_SUBJECT_ID. It's working fine.
LOV for CATEGORY_ID: I am making this LOV using a table CATEGORIES having FOUR columns. MY query is SELECT CATEGORY_ID, CATEGORY_NAME FROM CATEGORIES WHERE DOMAIN=:P4.8_DOMAIN_ID It's working fine.
LOV for STANDARD_CODE: I am making this LOV using a table CURRICULUM having MORE THAN EIGHT columns. MY query is SELECT CURRICULUM_ID CI, STANDARD_CODE SC FROM CURRICULUM WHERE SUBJECT=:P48_SUBJECT_ID AND GRADE_ID=:P48_GRADE_ID AND DOMAIN_ID=:P48_DOMAIN_ID AND CATEGORY_ID=:P48_CATEGORY_ID. It's not working for me.
Kindly tell me how I can correct the 5th LOV. Thanks
I wouldn't say that any of LoV queries you posted return desired result and "work fine". Their format should be:
select display_value, --> you see it on the screen
return_value --> you don't see it; it is stored into the table
from ...
Code you posted suggest just the opposite, e.g.
SELECT SUBJECT_ID, --> are you REALLY displaying ID to users and
SUBJECT_NAME --> storing NAME into the table?
FROM SUBJECTS
As of your final LoV: just as MT0 commented, we have no idea what "not working" means. You posted a whole lot of more or less useless information (queries that "work"; what should we do with them?), but said nothing about problem you have.
Therefore, I'll guess: you forgot to include
P48_SUBJECT_ID, P48_GRADE_ID, P48_DOMAIN_ID, P48_CATEGORY_ID
into the Parent Item(s) property within the "Cascading List of Values" section, e.g.
Note that query you posted presumes that all page items have a value; if any of these is NULL, query won't return anything so that would be my second guess:
SELECT curriculum_id ci, standard_code sc
FROM curriculum
WHERE ( subject = :P48_SUBJECT_ID
OR :P48_SUBJECT_ID IS NULL)
AND ( grade_id = :P48_GRADE_ID
OR :P48_GRADE_ID IS NULL)
AND ( domain_id = :P48_DOMAIN_ID
OR :P48_DOMAIN_ID IS NULL)
AND ( category_id = :P48_CATEGORY_ID
OR :P48_CATEGORY_ID IS NULL)
In that case, switch the "Parent required" property OFF.

I keep getting duplicate results

I'm new to SQL and I'm using Oracle Apex. I am trying to run the following query:
Select COMPANIES.COMP_NO as "Company Id", COMP_NAME as Company",
OPEN_START_DATE as "Start Date", OPEN_TITLE as "Opening Title",
QF_CODE as "Required Qualification"
From OPENINGS, COMPANIES
Where COMP_ADDRESS='Auckland'
AND OPEN_START_DATE Between '12/01/2016' AND '12/31/2016';
I know there should only be four returned results but I keep getting duplicates of the same entry. What am I doing wrong?? I believe it must be something to do with my table connections... Thanks
select
c.comp_no,
c.comp_name,
o.start_date,
o.open_title
from
companies c
join openings o on o.comp_no=c.comp_no
where
start_date between '2016-10-01' and '2016-10-07';
use join instead of selecting it in the from clause.

Fail to query a list corresponding another value in ADD ROW action

Please Help...
I am using Oracle Apex.
I created the FORM page with Master Details form, it has CW_ORDER and CW_SALESLINE table. There also is a CW_INVENTORY table.
When user press "Add Row" button, there will show two list boxes for choosing which 'TYPE' as Product type" and 'INV_ID' as Product Description".
TYPE as Product Type is configured "Select List(static LOV)"
with List of Value (STATIC:Hardware;Hardware,Software;Software)
User can choose 'Hardware' or 'Software' only.
INV_ID as Product Description is configured "Select List(query based LOV)
with List of Value (select description, inv_id from cw_inventory where cw_inventory.type = :type)
I want that when user chooses Product Type value such as 'Hardware' and then Product Description can list only the type of Hardware items for choosing instead of all items are listed.
In CW_Inventoty has a 'TYPE' column, its value is Hardware or Software.
I think the (select description, inv_id from cw_inventory where cw_inventory.type = :type) something wrong.
Please advise. Thank you so much .....
To achieve your above requirement,
you want to use cascading select list concept here in tabular form.
refer Cascading select list on tabular form for more details.

Top user of day, week, all time - best way to implement?

Suppose each user on my site has a score which increases as they use the site (like Stackoverflow) and I have a field score stored in the user profile table for each user.
Getting the top 10 users of all time is easy, just order by the score column.
I want to have "top 10 today", "top 10 this week", "top 10 of all time".
What's the best way to implement this? Do I need to store every single score change with a timestamp?
You would have to have a table that stored the increments and use a timestamp. I.E.
CREATE TABLE ScoreIncreases (
PrimaryKey UNIQUEIDENTIFIER,
UserId UNIQUEIDENTIFIER,
ScoreIncrease INT,
CreatedDate DATETIME)
Your query would then be something like
SELECT TOP 1 u.PrimaryKey, SUM(ScoreIncrease)
FROM Users u
INNER JOIN ScoreIncreases si ON si.Userid=u.PrimaryKey
WHERE DATEDIFF(day,si.CreatedDate,GETDATE()) = 0
GROUP BY u.PrimaryKey
ORDER BY SUM(ScoreIncrease) DESC