Spags
Spags

Reputation: 541

Oracle APEX - Conditionally Changing Text Color in a cell on an Interactive Report based on Contained Value?

Ok... So. I have an interactive report in APEX that displays data about documents in our system. Our documents are supposed to be reviewed every two years and there is a column in the table that contains the date that the document should be next reviewed by. We want to visually indicate either in the cell that contains the date, or another cell in the row, when the date reaches certain benchmarks (i.e. When the date is within 6 months of the current date, 3 months, 2, 1 etc.)

What I need to hopefully do is to change the color of the text (or background) of a specific cell based on either the value of that cell or the value of another cell in the same row. There would need to be a process or some function that does some computation to determine the span between the sysdate and the date contained in the cell... It does not necessarily need to calculate when the page is loaded but a daily or weekly process or something would be good.

Is it possible to set up processes or triggers that execute daily without human interaction? I also have a need to use the same functionality for sending reminder emails about these upcoming deadlines. (i.e. when a document is 6 months out from needing to be reviewed an email would be sent out, at 3 months, 2, 1 etc.)

Upvotes: 3

Views: 22781

Answers (2)

sven ras
sven ras

Reputation: 41

In an Interactive Report, you also can define REPORTS ( with HIGHLIGHTS), which will do the trick for you.

Choose button ACTIONS, Then FORMAT (on Pop-up) and the HIGHLIGHT

In HighLight you can give a Name, Type (Row or Cell), Background and Text Colour, and the COLUMN on which you want an OPERATOR and an EXPRESSION. You Apply the Highlight (Make Several Highlights /other-name when you need more than one colour-highlight depending on your EXPRESSION-s). Together with the most important Filters then SAVE it as a Report (First Primary).

After having defined the Primary Report you can take this as the basis-report. Make some other Reports (and save them) with other filters, but with the same Highlights as the Primary Report).

Have FUN with it.

Upvotes: 4

Tom
Tom

Reputation: 7028

Example with hiredate on emp: i'm about to colour the cells that are > 11000. (sysdate-hiredate ranges from about 10k to 12k). You could use a field you calculate in the query, or one you filled in through some procedure, doesn't matter :)

select empno, ename, job, mgr, hiredate, sal, comm, deptno, 
       trunc((trunc(sysdate)-hiredate)) to_colour_or_not 
  from emp

You will need 2 dynamic actions to colour rows in reports: an onload action, and an after refresh. If you skip the after refresh, rows won't be coloured after for example pagination, due to partial page refreshing.

Dynamic action one: After refresh on the region:

dynamic action: after refresh

True action:

After refresh: true action

$("td[headers='TO_COLOUR_OR_NOT']").each(function(){
alert($(this).text());
   if(parseInt($(this).text()) > 11000){
      $(this).css({"background-color":"red"});
   };
});

Example of using one column as a condition to colour another column. Always be carefull with what you test and what you test it for! For example, the hiredate column is a date, be sure to treat it as such if necessary! Further caution too: if your date format is set as DD-MON-YYYY, then you'd have to do the mapping for month to number (JAN = 1, DEC = 12)! Maybe it is an option to change the date format for this column even...

$("td[headers='HIREDATE']").each(function(){
   var i_date = $(this).text();
   //date format = MM/DD/YYYY
   //be carefull with date formats. 
   //in my case, i know my date format and know it won't change
   //my code is far from a complete parse of possible date values!
   var dMonth = i_date.substring(0, 2),
       dDay = i_date.substring(3, 5),
       dYear = i_date.substring(6);    
   var d = new Date(dYear, dMonth, dDay, 0, 0, 0, 0);

   if(d.getFullYear() <= 1981){
      //we are looping over TD elements. I want to colour the 
      //column ENAME in red when the condition is true for this row.
      //so, $(this) = TD element we loop with. parent = TR element,
      //then back to the children of the row
      $(this).parent().children("td[headers='ENAME']").css({"background-color":"red"});
   };
});

The second dynamic action: on load

Dynamic action: Onload

As true action, use the same code as the true action for the refresh.

With the JS you can do whatever you want: you just need to know which cells you wish to paint. Use the [headers=''] to target the cells you'd like (jquery selectors). Instead of the css(), you can use addClass for example, if that is more what you'd like.

Do mind: IRs come with built-in mouseover actions. This causes your painted cells not to show in their colour when there is a mouseover action. If you don't want this, you'd need another dynamic action for the mouseover/mouseleave events, and target those cells necessary.

As for scheduled jobs: check out DBMS_JOBS.

Upvotes: 4

Related Questions