Wednesday, 20 February 2013

Highlight IR row based on APP_USER


Highlight IR row based on APP_USER

Here is how you can highlight interactive report rows if column value is same as login user name.
I did get idea for this article from this OTN forum post.
First create interactive report.
In this example rows where manager name equals APP_USER value are highlighted.
I have used following query joining EMP and DEPT tables for interactive report:
1
2
3
4
5
6
7
8
9
10
11
12
13
SELECT e1.empno
    ,e1.ename
    ,e1.job
    ,e2.ename AS mgr -- Dynamic action use this column alias
    ,e1.hiredate
    ,e1.sal
    ,e1.comm
    ,d.dname
    ,d.loc
FROM emp e1
LEFT JOIN emp e2
    ON e1.mgr = e2.empno
JOIN dept d ON e1.deptno = d.deptno
Create dynamic action:
  • Name: Highlight based on APP_USER
  • Event: After Refresh
  • Selection Type: Region
  • Region: {select your report region}
  • Condition: No Condition
  • Action: Execute JavaScript code
  • Fire On Page Load: True
  • Code:
    1
    2
    3
    4
    5
    6
    this.affectedElements.find('table.apexir_WORKSHEET_DATA td[headers="MGR"]').each(function(i){
     var lThis=$(this);
     if(lThis.text()=="&APP_USER."){
      lThis.parent().children().css({"background-color":"#55A955"});
     }
    });
  • Selection Type: Region
  • Region: {select your report region}
Note! You need modify dynamic action JavaScript part td[headers="MGR"] according your report column alias.

When you loging to example application use username BLAKE, JONES or KING to see highlight in action.

APEX classic report "instant search"

Here is how trigger APEX classic report refresh when user stop entering to text field.
First create classic report to your page.
In this example I have used following query joining EMP and DEPT tables:
1
2
3
4
5
6
7
8
9
10
11
12
13
SELECT e1.empno
    ,e1.ename
    ,e1.job
    ,e2.ename AS mgr
    ,e1.hiredate
    ,e1.sal
    ,e1.comm
    ,d.dname
    ,d.loc
FROM emp e1
LEFT JOIN emp e2
    ON e1.mgr = e2.empno
JOIN dept d ON e1.deptno = d.deptno

When you create report set "Enable Search" to "Yes" on wizard "Report Attributes" page and select columns for search.


Go edit report attributes and add to "Page Items to Submit" text item created by report wizard.


Edit page attributes and add page JavaScripts Function and Global Variable Declaration:
1
var gTimer;
and to Execute when Page Loads:
1
2
3
$("#Px_REPORT_SEARCH").keypress(function(e){
 return e.keyCode!==13;
});
Replace Px_REPORT_SEARCH with text item name created by report wizard.

Create dynamic action:
  • Name: Report instant search
  • Event: Key Release
  • Selection Type: Item(s)
  • Item(s): {select text item created by report wizard}
  • Condition: JavaScript expression
  • Value:
    1
    this.browserEvent.keyCode!==13
  • Action: Execute JavaScript code
  • Fire On Page Load: False
  • Code:
    1
    2
    3
    4
    5
    6
    var lTrg=$(this.affectedElements);
    clearTimeout(gTimer);
    gTimer=setTimeout(function(){
     clearTimeout(gTimer);
     lTrg.trigger("apexrefresh");
    },900);
  • False Action: Execute JavaScript code
  • Fire On Page Load: False
  • Code:
    1
    2
    clearTimeout(gTimer);
    $(this.affectedElements).trigger("apexrefresh");
  • Selection Type: Region
  • Region: {select your report region}

Now run page and type to search text field. After small delay report is refreshed and shows your search result.

Show interactive report single row view after submit

Here is how you can open interactive report single row view after page submit or page load.

Example is based on my previous post Show detail report for IR single row view record and idea from Jim to show tabular form instead of report when go single row view. Unfortunately we did not get wizard created tabular form working on this case, but workaround is create so called "manual" tabular form.

NOTE! in this example we use undocumented IR JavaScript function gReport.controls.row. This function may change or not exists in coming APEX versions.

Comparing previous example change hidden item Px_CUSTOMER_ID
  • Source Used: Only when current value in session state is null
  • Source Type: Static Assignment (value equals source attribute)

Edit in earlier post created dynamic action "Hide detail report" and add true action
  • Action: Set Value
  • Fire On Page Load: False
  • Set Type: JavaScript Expression
  • JavaScript Expression:
    1
    null
  • Selection Type: Item(s)
  • Item(s): Px_CUSTOMER_ID

Create new dynamic action. Select Advanced:
  • Name: Go Single Row View
  • Event: Page Load
  • Condition: No Condition
  • Action: Execute JavaScript code
  • Code:
    1
    gReport.controls.row($v('Px_CUSTOMER_ID'));
  • Selection Type: None
Go edit dynamic action and add another true action
  • Action: Show
  • Fire On Page Load: False
  • Selection Type: Region
  • Region: {select your report/tabular form region}
Edit dynamic action and add condition type "Request=Expression 1" and enter to Expression 1 "GO_SINGLE_ROW"


Next edit your page branch that lead backto same page and add to Request "GO_SINGLE_ROW".

No comments:

Post a Comment