APEX 5 Authorization Scheme specific user - oracle

I am building an APEX 5 Application for a school. There is a page called "Course Information" and it includes several Classic Reports with information such as the class roster and testing schedule. I want to include a report with grades but I only want this region to be viewable by the teacher of the course. If I can get a hidden item on the page to be filled with the username of the teacher, can I build an authorization scheme that checks APP_USER against this item and only show the region if they match?
How would I accomplish this?

I would go about this slightly differently, and wouldn't use an Authorization Scheme for this particular requirement.
Base the report on a view which has the teacher's username as one of the columns. Put a where clause in the report SQL, e.g. select col1, col2, col3 from the_view where teacher_username = :APP_USER.
Put a Condition on the region using Rows returned based on something like select 1 from the_view where teacher_username = :APP_USER.
This way, the report region will only be rendered if the user is allowed to view the records in it.

The simplest option is to use server side condition, a function that returns Boolean, for that region. Just put
return :APP_USER = 'YOUR_TEACHER';
in there. Region will render only for your teacher. Of course, 'YOUR_TEACHER' should be substituted with his real username.

Related

Choose the first non-null field for each record in ServiceNow

How to create a view in ServiceNow that combines multiple columns (same data type) into one by picking the first non-null value? Note that it should not actually modify the underlying data.
After a search of the documentation I thought I had an answer with function fields, but GlideFunction doesn't seem to have nvl/coalesce as a function. The functionality called coalesce in ServiceNow seems to relate to importing/permanently modifying data only.
An example would be if you have employee and department, both of which have a location field. Show the employee's location unless it is null, otherwise show the employee's department's location.
In standard SQL, I would do it like this:
CREATE VIEW my_view AS (
SELECT COALESCE(employee.location,department.location) AS location
FROM employee JOIN department
ON employee.department_id = department.department_id
);
You have not mentioned how you are going to query this view. SNOW does not give us control over selection while designing views like the standard SQL.
Use GlideRecord to conditionally select the columns based on nullability.

Form WHERE clause

I have an APEX form I'm developing for "user settings". I have a table with a sequence as a primary key and the users ID in another column...in addition to a few columns where each users saved settings are stored (things like "N" for do not receive notices).
I haven't used Oracle APEX in a while so excuse this likely newbie question...The insert works fine, but I'm having trouble with making the form only show the current users values. In my Form Region the source is set to my Table, and I have a WHERE clause like this:
USER_ID = 813309
But that's not working (813309 is my id and I'm just hard-coding it for now). The form always comes up with a "New" record.
For a form to load a specific record you can set the primary key page item to the value you need. You can do so in the url using the link builder from another page or you can set a computation on the item. That is what I would try in your case: add a computation to your item P_USER_ID of type "Static Value" with value 813309. Make sure the computation happens before the "Fetch Row" - the value obviously needs to be set before the process runs.
In such cases, I prefer creating a Report + Form combination (using the Wizard, of course): it creates an interactive report (so that you can review data in a table), and a form which is used to add new records or update/delete existing ones.
Doing so, when you pick a user in interactive report and click the icon at the beginning of a row, Apex redirects you to the form page, passing primary key column value to the form which then fetches appropriate data from the table.
Not that it won't work the way you're trying to do it, it's just simpler if you let Apex do everything for you.
So: did you create an automatic row fetch pre-rendering process? If not, do so because - without it - Apex doesn't know what to fetch. Also, if you hardcoded user_id, it won't do much good. Consider storing username into the table so that you could reference it via :APP_USER Apex variable.

APEX_ITEM displays only one row

I have created a form region "Form on a SQL query" with this query
SELECT
APEX_ITEM.TEXT(1,TEAM_MEMBER) TEAM_MEMBER,
APEX_ITEM.TEXT(2,HOURS) HOURS
FROM APEX_TEAM_MASTER
WHERE TEAM_DATE = :P2_TEAM_DATE
AND UPPER(TEAM_LEAD) = UPPER(:P2_TEAM_LEAD)
ORDER BY 1
TEAM_MEMBER and HOURS are the exact columns in the APEX_TEAM_MASTER table
The :P2_TEAM_DATE and :P2_TEAM_LEAD are select lists. When i run the page and select values in the lists, the form displays just one row of text boxes.
The purpose of this page is, a manager can login to this application, select a date and a team lead under him, which lists the members under the lead. He can then record the hours each team member worked for the day. There are multiple team leads under each manager and different number of team members under each team lead. So the form has to be dynamic.
What you described looks more like an Interactive Grid (IG) (or former Tabular Form). There's no need for you to reinvent that functionality, so - switch to the IG and let Apex take care about everything else.

Creating a page to show data with foreign keys

I'm creating an APEX application that allows students to apply to job placements, and allows an admin to see all interactions. I want to create a page to show all of the students applications.
First off, here's the database schema for the tables involved:
Full sized link: http://i.stack.imgur.com/QU1Pr.png
I have a report with a list of students and I've added a "View Applications" column. I've made the "View Applications" column linkable, and it goes to the new page. The problem is, I have no idea how to show all of the applications for the student that the admin is currently looking up.
The only way I can think of doing it is passing RECORD_NUMBER (PK in students table) to the new page and then executing some SQL using that, and populating the page fields with what's returned. But I have no idea how to do that. I don't know how to grab the RECORD_NUMBER value to use in SQL and I don't know how to populate form fields with what's returned by the SQL.
Any help is appreciated.
So you've got one page that lists applications and the students that have applied. We'll call that page 1. If I understand what you're trying to do, you can create a page 2, with a report and a hidden page item. Call the page item P2_RECORD_NUMBER.
Create the report with the query:
SELECT *
FROM tbl_jobs j
INNER JOIN tbl_applications a on a.job_id = j.id
INNER JOIN tbl_students s ON s.record_number = j.record_number
WHERE s.record_number = :P2_RECORD_NUMBER
Now edit the link on page 1 so it points to page 2 and populates P2_RECORD_NUMBER with the record_number of the row that the user clicked on. I don't have Apex in front of me, but I think you can do that by editing the report attributes for that column. Also, you can use the url of the form http://site.com/f?p=<APP_ID>:<PAGE_ID>:0::::P2_RECORD_NUMBER:<record_number>. (I'm doing that from memory and may have the number of colons wrong.)
You'll also want to have some default text in place in case the query above returns no rows.
Just create a new page for the admin and enter a query like
SELECT *
FROM tbl_students s
JOIN tbl_applications a USING (record_number)
JOIN tbl_jobs j ON a.job_id = j.id
Do you know where to add the query?

FileMaker Pro -- Filtering Relationship Not Working

I'm trying to build a FileMaker Pro 11 layout that excludes records containing a certain value. The relevant data is in table Invoice. I want to filter so that Invoice records whose "Invoice Check Grouping" field is blank are not displayed on the layout.
I've added a global field to the invoice table called "Blank Invoice Check Grouping" to use as my filter criteria. I've created a self-join relationship to the Invoice table, joining "Invoice ID" to "Invoice ID" and joining "Invoice Check Grouping" to "Blank Invoice Check Grouping". The resulting table is named "Invoice Check Groupings".
The layout which I build based on table "Invoice Check Groupings" shows all records in Invoice--it does not filter out those with blank values. What am I doing incorrectly?
Thanks,
Ben
Layouts show records in a table (or more accurately, a table occurrence) and don't directly deal with related data. As mentioned by #pft221, you can use relationships for filtering, but only when viewing data through a portal.
If you always want a particular layout to show data based on a particular find, you can do so with a script and a script trigger. First set up a script to do the following:
Enter Find Mode[]
Set Field["Invoice Check Grouping"; "*" // Find all records with any data in this field
Perform Find[]
Note that you can also embed the find request within the Perform Find script step, but I tend to script finds in the above manner as it's easier to see what the find request is in the script and variables can be used in the find request.
Now you need to set your layout to execute this script whenever it's loaded. Go to the layout and enter Layout Mode. Select Layouts>Layout Setup from the menu bar. Click the Script Triggers tab and check the box for OnLayoutEnter and select the script you wrote above. Now whenever the layout is entered, that script will run and exclude the records that have that particular field being empty.
There are many ways to filter records, depending on what you are trying to do and what you are trying to display for your users.
The most common and simple way you can filter records is through a simple Find in a list view. I'm unclear from your question, but my best guess is that you're already using a list view and misunderstanding how FileMaker's relationships and Table Occurrences (TO's) work.
To Filter with the "Find Records" method:
Create a new List View layout of any Table Occurrence of your Invoice Table -- most likely you will want to use the default Table Occurrence that FileMaker created for you when you created the table.
Place the fields that you would like to display on that layout, including the "Invoice Check Grouping" field.
Switch into Find Mode
Put a '*' character into the "Invoice Check Grouping" field
Perform the Find
You should now see a list of all Invoices where the "Invoice Check Grouping" field is not blank. (You can find additional interesting search criteria in the "Insert: Operators" drop down of the title bar.)
Now you may actually be looking to filter related records through a portal but, given that you've set up a self-join on the Invoice index on the Invoice table my guess is that, at best, this would show either 0 or 1 record for each Invoice record you display in your main layout.
To Filter Records with the "Portal Filter" method:
Let's assume, though, that you have a Client table where you'd like to see only the records with a non-blank "Invoice Check Grouping" value. The table set-up would be as follows:
Client
Client ID
[... other client info ...]
Invoice
Invoice ID
Client ID
Invoice Check Grouping
[... other invoice info ...]
With a relationship in the relationships graph:
Client::Client ID ------< Invoice::Client ID
From there you would set up a Form layout on the Client TO and create a portal showing records from the Invoice TO. From the options for the portal you would select "Filter Portal Records" and use a formula similar to:
not IsEmpty(Invoice::Invoice Check Grouping)
Finally, it's worth noting that a portal filter isn't appropriate for all display situations or calculations. You can set up a similar filter completely through your relationships graph (as I believe you have already tried to do.) This will work, once again, for viewing records through a portal but not for the records displayed by a layout itself.
The answers above don't actually help Ben with his question. They are workarounds.
I have the same problem as Ben, and I don't think there is a solution, even now in Filemaker 12. There is I think no way to define a relationship that will omit the related records where the match fields are empty.
Two options come to mind:
On a specific layout, you have more fine-grained control in the portal definition itself, and can use this to exclude the records
You can now use SQL queries to achieve this result within Filemkaer.

Resources