Defining and deploying a dynamic template for output XML

If you want to use a template that contains a subset of the elements in the standard output template, create a dynamic output template.

About this task

If you want the ability to remove some elements from the standard template and perhaps add your own elements, you do that by passing your XML data or a file name into the YFSEnvironment object.

To define and deploy a dynamic template:

Procedure

  1. Copy the standard output template for the API that you want to modify from the <runtime_sandbox>/repository/xapi/template/merged/api/FileName.xml file as <runtime_sandbox>/extensions/global/template/api/FileName.xml.

    When naming your new template file, use the same name as the standard template

    The name of the output template corresponds with the name of the API or event associated with it. For example, the getOrderDetails() API takes the output template file getOrderDetails.xml.

  2. Modify the copied template in the /extensions/global/template/api directory as required, keeping in mind the best practices for creating custom output XML templates.
  3. During user interface extensibility, call the setApiTemplate() function on the YFSEnvironment object. This enables you to specify an output template before calling an API, using one of the following functions:
    • XML data as a variable - as in the following example:
      YFSEnvironment env = createEnv();
      Document doc = getTemplateDocument();
      env.setApiTemplate("getOrderDetails", doc);
      private YFSEnvironment createEnv() {
      //create new environment by passing the user id, program id, etc.
      }
      private Document getTemplateDocument() {
      //create a Document object containing the desired template XML.
      }
      
    • XML file as a variable - as in the following example:
      YFSEnvironment env = createEnv();
      env.clearApiTemplates();
      env.setApiTemplate("getOrderDetails", "myOrderDetails");
      private YFSEnvironment createEnv() {
      //create new environment by passing the user id, program id, etc.
      }

      The API then uses the template passed in through YFSEnvironment to produce the output XML document. For details about the YFSEnvironment interface, see the Javadoc.