ReadReportFile

You can use the ReadReportFile function to retrieve .xslt files and modify the XML sent to reports.

When to use

You can use this function to:

  • Read XSLT files to transform XML data before sending reports in secured mode.
  • Load report template files, such as XSLT and configuration files, for dynamic report generation.
  • Perform file operations in memory without writing temporary files to disk.
  • Retrieve centrally stored report files from the configured web reports server location.

Syntax

string ReadReportFile(string fileName);

Parameters

Parameter Type Required Description
fileName string Yes The name of the file to read. for example, "Approve.txt", "AttributeRemove.xsl". No file path is specified.

Return Value

The application returns the contents of the specified file as a string.

Working

  1. Web.config Configuration

    The API reads the Web.config option to identify the Web Reports server:

    https://%3Cadd%20key=%22SvcReportServerName%22%20value=%22your%20server%22%20/%3E

  2. File Location
    The method retrieves the file from the following location on the configured Web Reports server:

    https:////%3CReportServerName%3E/Source/%3CtenantID%3E/

    • ReportServerName: The Web Reports server configured in Web.config.
    • tenantID: The name displayed in the drop-down list on the Optiva Login page.
  3. Return Data
    The application returns the file data as a string. The function call does not specify a file path.

Prerequisites

  • The SvcReportServerName must be configured in Web.config.
  • The files are tenant-specific and isolated by tenantID.
  • Specify only the file name. The file path is determined by the configuration.
  • The function is intended for text-based files, such as XSLT, XML, and TXT files.

Examples

Example 1
Read Text File
// Read text file
string res = ReadReportFile("Approve.txt");
MessageList(res);

// Message displays the file contents
Description
When you run the Action, a message is displayed. The message shows the contents of the noted file.
Example 2
XSL Transform Workflow Script
public long wf_start()
{
    // Get original XML from object
    string xmlOrig = ObjectXML(_ObjectSymbol, _ObjectKey, "HEADER");
    MessageList("XML Orig: ", xmlOrig);
    
    // Create helper and perform XSL Transform
    XSLTransformHelper helper = new XSLTransformHelper(this);
    string xmlNew = helper.DoXSLTransform("AttributeRemove.xsl", xmlOrig);
    MessageList("XML New: ", xmlNew);
    
    return 9111;
}
Description
This script library and workflow script demonstrates how to perform an XSL Transform in a secured mode.

XML transform example

This script library and workflow script demonstrates how to perform an XSL Transform in a Secured Mode. This sample script uses the ReadReportFile method to perform an XSL Transform.

Security Benefits
  • The files are processed in-memory, not written to disk.
  • The XSL Transform is performed in a secured environment.
  • Eliminates security risks from disk file operations.
  • The files stored in controlled web reports server location.

This is an example of a workflow script that uses the sample script library:

Example 3
XSLTransformHelper Script Library.
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Xsl;

public class XSLTransformHelper
{
    private FcProcFuncSetEvent co;
    
    public XSLTransformHelper(FcProcFuncSetEvent context)
    {
        co = context;
    }
    
    public string DoXSLTransform(string XSLTFileName, string XMLText)
    {
        // Read XSLT file from Web Reports server
        string xslText = co.ReadReportFile(XSLTFileName);
        
        if (string.IsNullOrWhiteSpace(xslText))
        {
            throw new ArgumentNullException("XSLTFileName", "DoXSLTransform missing or blank XSLT stylesheet.");
        }
        
        // Load XSL Transform
        XslCompiledTransform xslTransform = new XslCompiledTransform();
        
        try
        {
            using (StringReader srXSLT = new StringReader(xslText))
            using (XmlReader xrXSLT = XmlReader.Create(srXSLT))
            {
                xslTransform.Load(xrXSLT);
            }
        }
        catch (Exception exXSLT)
        {
            throw new Exception("DoXSLTransform: Failed to load XSLT stylesheet.", exXSLT);
        }
        
        // Perform XML transformation
        StringBuilder xmlOutBuilder = new StringBuilder();
        
        try
        {
            using (StringWriter swXML = new StringWriter(xmlOutBuilder))
            {
                XmlWriterSettings wsXML = new XmlWriterSettings();
                wsXML.OmitXmlDeclaration = true;
                
                using (XmlWriter xwXML = XmlWriter.Create(swXML, wsXML))
                using (StringReader srXML = new StringReader(XMLText))
                using (XmlReader xrXML = XmlReader.Create(srXML))
                {
                    xslTransform.Transform(xrXML, xwXML);
                }
            }
        }
        catch (Exception exXSLT)
        {
            throw new Exception("DoXSLTransform: Failed to transform.", exXSLT);
        }
        
        return xmlOutBuilder.ToString();
    }
}
}