Sample from results of a Quick Search

You can run Web Reports from a Quick Search. However, the results from quick searches are not added to the dataset (and thereby into the XSD) until the search is executed from the workflow (by using the EXECUTE object method).

This workflow example demonstrates how to add search results data from a Web Client Quick Search to a Web Report.

' This executes the search and adds the Result detail object to the
dataset.
Dim dsQS As DataSet = ObjMethod("FORMULASEARCH.HEADER;CRITERIA",_ObjectKey
"ObjectMethod", "EXECUTE","" )
‘ To export the XML for the search object, add this line after the
ObjMethod call.
Dim XMLStr As String = ObjectXML("", "", "HEADER;RESULTS")
When you write a report on search results, or a report that includes data from related objects(ingredients, parameters, references, etc.) you build an xml that lists each object xml at the same node level, for example:
Project 1
Project 2
Project 3

Or

Formula1
Item1
Item2
Item3

In many cases, validation within the software avoid the possibility of duplicates (for example, parameters on any object, or references). However, there are common ways that the data set can end up with duplicate members:

  • The same item or subformula can be used multiple times on a formula or specification
  • Search results bringing along referenced data can have the same references such as customer or vendor.

    Then, the XML includes redundant entries. For example:

    Project 1
    Customer Z
    Project 2
    Customer Y
    Project 3
    Customer Z

The result is the report generation failing and giving errors.

You must consider whether there is any possibility of redundant xml, and code around that in the workflow.

Tips

  • The ObjMethod command is needed to run the search within the script. Otherwise, search results are cleared upon initiating a workflow without this.

  • Datatable functions needed to parse the search results and get data into xml.

  • When writing the report, group by search result records and the schemas that are needed. For example, no search result schema is ever used unless search constraints are desired in the report.

  • Add the foreign object’s xml to the file, not just an entry in FsFormulaingred or FsProjectRef.

Example of report for Quick Search results

This example is for illustration purposes only. For further clarification about implementation, contact an Optiva implementation consultant.

Note: 

This report brings in referenced data schemas. The run-time can be very slow. Therefore, it is not advised to use significant referenced data in search result reports.

  • In the example, the text highlighted in blue is specific to Quick Search results. An object method runs the search results from within the script to make the report work. This is necessary information for writing a report against Quick Searches.

  • The portion showing the use of hashtables to track what has been identified for addition to the xml is highlighted in red. There is a name space that needs to be added to support this. Some of the name spaces that are out of the ordinary are for the Quick Search. There are two sets of text in red but they are essentially the same – one brings in referenced formulas, the other brings in referenced customers.

  • ObjectsXMLForeign is a shortcut to the for next loops for adding referenced xmls. This can be useful in many cases. However, if there is a chance for duplicate entries, it should not be used because it bypasses the chance to exclude data from the xml.

  • Because of space limitations in the document, some function lines wrap but should be entered on a single line in the Action form.

Option Strict Off
imports System 'This namespace has use for Exception class (error handling, Array,
DBNull)
imports System.Data 'Needed by ObjMethod that executes the report
imports System.Diagnostics 'Optional
imports System.Text.RegularExpressions 'Needed for regex command
imports System.XML
imports System.Net 'Use if calling a web service on another product, like HTTP to
Web Reports
imports System.Configuration 'Code can read .Net config files like Optiva.Config or
Web.Config
imports System.Collections
Class ActionScript
inherits FcProcFuncSetEventWF
Function wf_start() As Long
Dim addedCust As New Hashtable
Dim addedFormulas As New Hashtable
'Part 1 - initial declarations and file path
'==============
Dim xdTemplate as New XmlDocument '
Dim xfXMLobject as XmlDocumentFragment
Dim xnRoot as XmlNode, xnXmlNode as XmlNode
Dim sTemplate, sFilePath, sXML, sXn, sFileName, sFileNameExt, sDocFilePath,
sFuncCodeName, sFileAttach as string
dim xmlname as string = "EHQuickSearch1.xml"
dim rptname as string = "EHQuickSearch1.rpt"
'Set the File Path to the location in which the Web Reports are installed.
sFilePath = "C:\Inetpub\wwwroot\FsWebReports\"
'================
'Part 2 - define schema list (generate schemas here or name pre-defined schemas)
'================
'Create a template XML file to contain the report data. Include the schema names to
use for the report.
sTemplate = "<fsxml><report><SchemaList><Schema>PROJECT_ALL.xsd</
Schema><Schema>FORMULA1.xsd</Schema><Schema>COMPANY1.xsd</Schema></
SchemaList><object /></report></fsxml>"
xdTemplate.LoadXml(sTemplate)
'================
'Part 3 - Define XML details for the object(s) in question. Use only what is
needed.
'================
'Create an XML file for the object. Specify details to include.
'---Quick Search Logic
Dim dsQS As Dataset = Workflow.ObjMethod("QUICKSEARCH.HEADER;CRITERIA",
_OBJECTKEY, "ObjectMethod", "EXECUTE", "")
If not dsQS Is Nothing AndAlso
dsQS.Tables.Contains("FSQUICKSEARCHSEARCHRESULT_0") Then
Dim tblSummaryResults As DataTable =
dsQS.Tables("FSQUICKSEARCHSEARCHRESULT_0")
For Each rowSummaryResult As DataRow In tblSummaryResults.Rows
Dim projectCode As Object = rowSummaryResult("PROJECT_CODE")
DIM pclass as object = ObjProperty("CLASS","PROJECT",projectCode)
sXML = ObjectXML("PROJECT", projectCode,
"HEADER;ST;STATUS;REF;CONTEXT;TPALL")
'================
'Part 4 - make modifications to the xml
'================
'Strip leading and trailing <fsxml> tags before loading XML fragment
sXML = System.Text.RegularExpressions.Regex.Replace(sXML, "(<|</)fsxml.*?>",
"")
'================
'Part 5 - some xml gymnastics to put things together correctly
'================
'Allows inserting all XML(s) into the template without having to code a for/next
loop
xfXMLobject = xdTemplate.CreateDocumentFragment()
xfXMLobject.InnerXml = sXML
'Find the XML node to insert the report data into.
xnRoot = xdTemplate.SelectSingleNode("/fsxml/report/object")
'Insert the object data into the template XML file.
xnRoot.AppendChild(xfXMLobject)
'Add other schemas here, e.g. referenced objects
'-------------------------
dim formulas as object = Workflow.ObjProperty("OBJECTCODE.REF.V\REFPROJECT1",
"PROJECT",projectcode,"*",1)
if not formulas is nothing andalso isdbnull(formulas)=false
'Workflow.MessageList("there are ",formulas.length, "formulas on project ",
projectcode)
dim x as integer
for x = 0 to ubound(formulas)
If Not addedFormulas.Contains(formulas(x)) Then
Dim XnFormula As String
XnFormula = ObjectXML("FORMULA", formulas(x),"HEADER;INGR;STATUS;TPALL")
'Strip leading and trailing <fsxml> tags before loading XML fragment
XnFormula = System.Text.RegularExpressions.Regex.Replace(XnFormula, "(<|</)
fsxml.*?>", "")
'Allows for inserting all of the XML(s) into the template without having to
code a
'for/next loop
xfXMLobject.InnerXml = XnFormula
'Insert the object data into the template XML file.
xnRoot = xdTemplate.SelectSingleNode("/fsxml/report/object")
xnRoot.AppendChild(xfXMLobject)
addedFormulas.Add(formulas(x),cstr(x))
end if
next x
end if
'-------------------------
'-------------------------
dim customers as object =
ObjProperty("OBJECTCODE.REF.V\REFPROJECT9","PROJECT",projectcode,"*",1)
if not customers is nothing andalso isdbnull(customers)=false
dim z as integer
for z = 0 to ubound(customers)
If addedCust.ContainsKey(customers(z)) = false Then
Dim XnCustomer As String
XnCustomer = ObjectXML("COMPANY", customers(z),"HEADER;STATUS")
'Strip leading and trailing <fsxml> tags before loading XML fragment
XnCustomer = System.Text.RegularExpressions.Regex.Replace(XnCustomer, "
(<|</)fsxml.*?>", "")
'Allows inserting all XML(s) into the template with no code a for/next loop
xfXMLobject.InnerXml = XnCustomer
'Insert the object data into the template XML file.
xnRoot = xdTemplate.SelectSingleNode("/fsxml/report/object")
xnRoot.AppendChild(xfXMLobject)
addedCust.Add(customers(z),customers(z))
end if
next z
end if
'-------------------------
'end addition of referenced object schema
Next
End If
'================
'Part 6 - save to a .xml file
'================
'Save XML output to C:\Inetpub\wwwroot\FsWebReports\sessionXml directory.
xdTemplate.Save(sFilePath & "SessionXML\" + xmlname)
'================
'Part 7 - generate the report!
'================
'Combine XML data with Crystal report template; display in desired format, save to
'desired folder replace {report name} and {xml name} with actual xml and rpt file
names
'Select syntax below depending on output in pdf, doc, or xls.
' PDF format
' Workflow.ShellAPI("http://the_server_name/FsWebReports/Launch.aspx?
' p1={xml name}.xml&p2=FORMULA&p3=pdf&p4=" & sFilePath & "Source\
' {report name}.rpt")
' sFileNameExt = sFileName & ".pdf"
' MS Word format
' Workflow.ShellAPI("http://the_server_name/FsWebReports/Launch.aspx?
' p1={xml name}.xml&p2=FORMULA&p3=MSWORD&p4=" & sFilePath & "Source\
' {report name}.rpt&p5=" & sDocFilePath & sFileName & ".doc")
' sFileNameExt = sFileName & ".doc"
' MS Excel format
' Workfloww.ShellAPI("http://the_server_name/FsWebReports/Launch.aspx?
' p1={xml name}.xml&p2=FORMULA&p3=EXCEL&p4=" & sFilePath & "Source\
' {report name}.rpt&p5=" & sDocFilePath & sFileName & ".xls")
' sFileNameExt = sFileName & ".xls"
'The actual functioning command:
Workflow.ShellAPI("http://localhost/FsWebReports/Launch.aspx?p1=" & xmlname &
"&p2=FORMULA&p3=pdf&p4=" & sFilePath & "Source\" & rptname & "&p5=" & sDocFilePath
&
sFileName & ".pdf") sFileNameExt = sFileName & ".pdf"
'================
return 111
End Function
End Class