01.02.2013 Views

Publishing Reports to the Web - Downloads - Oracle

Publishing Reports to the Web - Downloads - Oracle

Publishing Reports to the Web - Downloads - Oracle

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Invoking a Report From a Database Event<br />

One way you can display this information is by setting SERVEROUT <strong>to</strong> ON in<br />

SQL*PLUS before you run your script.<br />

In addition <strong>to</strong> this method of debugging, <strong>the</strong> API has a set of pre-defined exceptions <strong>to</strong><br />

be used for error handling. You'll find examples of <strong>the</strong>se exceptions in <strong>the</strong> srw_test.sql<br />

script provided with your <strong>Oracle</strong>AS <strong>Reports</strong> Services installation. Additionally, see <strong>the</strong><br />

<strong>Oracle</strong> <strong>Reports</strong> API reference documentation for a detailed explanation of <strong>the</strong>se<br />

exceptions.<br />

Note: Look for upcoming information about <strong>Reports</strong> APIs on <strong>the</strong><br />

<strong>Oracle</strong> Technology Network, (http://otn.oracle.com).<br />

17.3 Invoking a Report From a Database Event<br />

Database triggers are <strong>the</strong> primary mechanism for invoking reports using <strong>the</strong><br />

Event-Driven <strong>Publishing</strong> API. The <strong>Oracle</strong> database allows you <strong>to</strong> define various scopes<br />

of triggers that fire in response <strong>to</strong> various events. To submit a database-driven job, you<br />

use <strong>the</strong> code described in <strong>the</strong> previous sections within a database trigger.<br />

There are many ways <strong>to</strong> use event-driven publishing. One way is <strong>to</strong> create security<br />

pro<strong>to</strong>cols using a trigger that fires whenever a grant is done or a user logs on or off.<br />

Ano<strong>the</strong>r way is <strong>to</strong> create au<strong>to</strong>mated processes that respond <strong>to</strong> certain types of changes<br />

<strong>to</strong> data in a table. For example, a database trigger could fire when <strong>the</strong> status of an<br />

expense report changes <strong>to</strong> DONE; in turn, a report could au<strong>to</strong>matically be sent <strong>to</strong> an<br />

employee's manager.<br />

For example:<br />

CREATE TRIGGER EXP_REP_TRG<br />

AFTER INSERT OR UPDATE on EXP_REP FOR EACH ROW<br />

myPlist SRW_PARAMLIST;<br />

myIdent SRW.JOB_IDENT;<br />

BEGIN<br />

IF (:new.ExpStat = 'DONE') THEN<br />

myPlist := SRW_PARAMLIST(SRW_PARAMETER('',''));<br />

SRW.ADD_PARAMETER(myPlist,'GATEWAY','http://…');<br />

SRW.ADD_PARAMETER(myPlist,'SERVER','fooSVR');<br />

SRW.ADD_PARAMETER(myPlist,'REPORT','foo.RDF');<br />

SRW.ADD_PARAMETER(myPlist,'USERID','foo/bar');<br />

SRW.ADD_PARAMETER(myPlist,'ExpenseID',:new.ExpID);<br />

myIdent := SRW.RUN_REPORT(myPlist);<br />

END IF;<br />

END;<br />

This trigger will fire after each update on <strong>the</strong> EXP_REP table. In <strong>the</strong> event <strong>the</strong> status<br />

changes <strong>to</strong> DONE, <strong>the</strong> report request is run.<br />

If you want your request <strong>to</strong> run against a key specified in <strong>the</strong> cgicmd.dat file, specify<br />

<strong>the</strong> CMDKEY parameter in lieu of <strong>the</strong> REPORT parameter. If <strong>the</strong> key contains user ID<br />

information, you can omit <strong>the</strong> USERID parameter as well. For example:<br />

CREATE TRIGGER EXP_REP_TRG<br />

AFTER INSERT OR UPDATE on EXP_REP FOR EACH ROW<br />

myPlist SRW_PARAMLIST;<br />

myIdent SRW.JOB_IDENT;<br />

BEGIN<br />

IF (:new.ExpStat = 'DONE') THEN<br />

myPlist := SRW_PARAMLIST(SRW_PARAMETER('',''));<br />

SRW.ADD_PARAMETER(myPlist,'GATEWAY','http://…');<br />

17-6 <strong>Oracle</strong> Application Server <strong>Reports</strong> Services <strong>Publishing</strong> <strong>Reports</strong> <strong>to</strong> <strong>the</strong> <strong>Web</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!