Digital beach
My little place on the web
Digital beach Blog / Articles Categories XML Publisher Using triggers with XML Publisher
Using triggers with XML Publisher
Written by Patrick van Zweden   

Sometimes there are certain actions that need to be performed before an XML report is produced. Or certain actions have to be performed after an XML report has run (updating values in a table, kicking off the bursting engine, etc).

In the past these kind of actions were accomplished by using beforeReport and afterReport triggers in the Oracle Reports report. With the rise of XML publisher as the recommended way for producing reports it may seem that this triggers are gone.

Fortunately this is not the case. There's still the option of using beforeReport and afterReport triggers, even if you're only using an XML template to define the XML publisher report.
The trick is to create an XML data template which calls the triggers. The following example does exactly this.

  3. <dataTemplate name="D_EXAMPLE1" description="Example of before and after trigger"
  4. defaultPackage="xxpvz_reporting*">
  5. <parameters/>
  6. <dataQuery>
  7. <sqlStatement name="Q1">
  8. <![CDATA[ select 1 field1 from dual
  9. ]]>
  10. </sqlStatement>
  11. </dataQuery>
  12. <dataTrigger name="beforeReport" source="xxpvz_reporting.init()"/>
  13. <dataStructure>
  14. <group name="G_EXAMPLE" source="Q1">
  15. <element name="FIELD1" value="FIELD1"/>
  16. </group>
  17. </dataStructure>
  18. <dataTrigger name="afterReport" source=""/>
  19. </dataTemplate></p><p>

 The functions called in the dataTrigger sections need to return a Boolean value. When true is returned XML publisher "knows" all went well with the trigger. However when you return false XML Publisher will detect the trigger reported an error and will not continue. The concurrent program will get into an error state and the report will not be generated.

The example code below will start the bursting engine for the current report.

  3. l_result BOOLEAN;
  4. l_proc_name VARCHAR2(240) := 'post';
  5. l_req_id NUMBER;
  6. hr_utility.set_location('Entering: '||g_package_name||'.'||l_proc_name, 10);
  8. hr_utility.trace('Try to submit bursting request');
  10. l_req_id := fnd_request.submit_request (
  11. application => 'XDO'
  12. ,program => 'XDOBURSTREP'
  13. ,description => 'Bursting output'
  14. ,start_time => ''
  15. ,sub_request => FALSE
  16. ,argument1 => fnd_global.conc_request_id
  17. ,argument2 => 'Y'
  18. );
  20. IF l_req_id != 0 THEN
  21. l_result := TRUE;
  22. hr_utility.trace('Failed to launch the bursting request');
  24. -- Put message in log
  25. fnd_file.put_line(fnd_file.LOG, 'Failed to launch bursting request');
  27. -- Return false to trigger error result
  28. l_result := FALSE;
  30. hr_utility.set_location('Leaving: '||g_package_name||'.'||l_proc_name, 10);
  32. RETURN l_result;
  33. END post;

 So the triggers are still there and can be used. Just specify them in the data template.