Question
· Jul 21, 2016

Create dfi files (dashboards) programmatically

Hello, guys. 

Is there a way to create a dashboard programatically?

I have a source code of a dashboard in udl format and I need to somehow import it in my project. 

%Compiler.UDL.TextServices works only with classes and  ##class(%Routine).%New("dashboard.dfi") doesn't work as well. 

Discussion (1)0
Log in or sign up to continue

Here's some documentation that might be helpful (if you're looking for a better solution): Packaging DeepSee Elements into Classes

It's also possible to export .DFI files directly with $System.OBJ.Export and reload with $System.OBJ.Load, same as with classes/routines.

Back to your actual question - what do you mean by "source code of a dashboard in udl format"?

If you mean a file containing the same XML you see in Studio - e.g.:

<?xml version="1.0"?>

<pivot xmlns="http://www.intersystems.com/deepsee/library" name="test2" folderName="" title="" description="" keywords="" owner="" shared="true" public="false" locked="false" resource="" timeCreated="2016-07-21T12:43:26.593Z" createdBy="tleavitt" category="" bookCover="" mdx="" cellWidth="120" columnHeaderStyle="" rowHeaderStyle="" cellStyle="" rowLabelSpan="true" columnLabelSpan="true" cellHeight="22" showEmptyRows="false" showEmptyColumns="false" cubeName="" caption="" listing="" listingRows="" showStatus="true" pageSize="100" colorScale="" rowTotals="false" columnTotals="false" rowTotalAgg="sum" columnTotalAgg="sum" rowTotalSource="page" showZebra="false" showRowCaption="true" printTitle="" printSubtitle="" printSubtitleOn="" showUser="" printPageSize="" printOrientation="" printMarginTop="" printMarginLeft="" printMarginRight="" printMarginBottom="" printLabelWidth="" printCellWidth="" autoExecute="true" manualMode="false" userMDX="" chartMarginTop="" chartMarginLeft="" chartMarginRight="" chartMarginBottom="" maxRows="" borderLeftCell="" borderRightCell="" borderTopCell="" borderBottomCell="" borderLeftCol="" borderRightCol="" borderTopCol="" borderBottomCol="" borderLeftRow="" borderRightRow="" borderTopRow="" borderBottomRow="" fontFamilyCell="" fontSizeCell="" fontFamilyCol="" fontSizeCol="" fontFamilyRow="" fontSizeRow="" showFilters="" showListingFilters="" showDate="" listingFontSize="" showZebraStripes="" filterTableStyle="" filterTableCaptionStyle="" filterTableItemStyle="" nowDisplayFormat="" measureLocation="" hideMeasures="" backgroundImage="" backgroundOpacity=".12">
  <rowAxisOptions spec="" key="" value="" text="" headEnabled="true" headCount="" filterEnabled="true" filterExpression="" orderEnabled="false" orderExpression="" orderDirection="BDESC" aggEnabled="false" aggFunction="" aggFunctionParm="" levelCaption="" levelFormat="" levelSummary="" levelType="" drillLevel="0" advanced="false" levelStyle="" levelHeaderStyle="" suppress8020="false" drilldownSpec="" enabled="true">
  </rowAxisOptions>
  <columnAxisOptions spec="" key="" value="" text="" headEnabled="true" headCount="" filterEnabled="true" filterExpression="" orderEnabled="false" orderExpression="" orderDirection="BDESC" aggEnabled="false" aggFunction="" aggFunctionParm="" levelCaption="" levelFormat="" levelSummary="" levelType="" drillLevel="0" advanced="false" levelStyle="" levelHeaderStyle="" suppress8020="false" drilldownSpec="" enabled="true">
  </columnAxisOptions>
</pivot>

You could import it using %DeepSee.UI.FolderItemDocument:

Class User.DFIImport
{

/// Example use:
/// Do ##class(User.DFIImport).ImportDFIXML("foldername-itemname.pivot.DFI","C:\Temp\somefile.xml")
ClassMethod ImportDFIXML(pName As %String, pFilename As %String) As %Status
{
    Set tSC = $$$OK
    Try {
        set tStream = ##class(%Stream.FileCharacter).%New()
        set tSC = tStream.LinkToFile(pFilename)
        If $$$ISERR(tSC) { Quit }
        set tDoc = ##class(%DeepSee.UI.FolderItemDocument).%New(pName)
        set tSC = tDoc.ImportFromXML(tStream)
        If $$$ISERR(tSC) { Quit }
        set tSC = tDoc.Save()
        If $$$ISERR(tSC) { Quit }
    } Catch e {
        Set tSC = e.AsStatus()
    }
    Quit tSC
}

}

Note that the name specified for the %DeepSee.UI.FolderItemDocument will overwrite the "name" and "folderName" in the XML.