03-25-2024 11:17 AM
Hi All,
I have a process that exports a dashboard and all of its components to XML. It then reads through the XML and creates new objects. The process works when I import the XML by hand. I was wondering if there is a way to have the code:
1) delete objects if they exist
2) import the XML to create the new objects.
Thank you,
Scott
03-25-2024 11:28 AM
The only method I know that will effectively replace Dashboards is XFProject. Have a look in the Design and Reference Guide and search this forum for more info. This screenshot gives you an idea:
03-25-2024 11:41 AM
I had looked at that. Do you know if there a method to import and export the xfProj via code?
03-25-2024 12:08 PM
XFProj has its own XML library: XFProjectWcf
Use XFProjectWcf.ExtractXFProjectFileHierarchy to extract, and XFProjectWcf.StartLoadXFProjectFileHierarchy using similar structure to the code posted for application zip and dashboards.
03-25-2024 12:16 PM
and here is some code I've used in the past, maybe it can help you get started:
Using dbconnfw As DbConnInfo = BRApi.Database.CreateFrameworkDbConnInfo(si)
Using dbconnApp As DbConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
'Get the solution code 3 digit identifier
Dim solutionCode As String = BRApi.Dashboards.Parameters.GetLiteralParameterValue(si, False, "HelpAboutSolutionCode_AMGH")
'Inzialize the zip object
Dim xfprojObj As New XFProject()
xfprojObj.DefaultZipFileName = $"{datetime.Now:yyyyMMddHHmm}_{solutionCode}"
xfprojObj.TopFolderPath = solutionCode
'OBJECTS LIST
'Business Rules
Dim businessRulesList As List(Of String) = BRApi.Database.ExecuteSql(dbconnapp, $"SELECT DISTINCT Name FROM BusinessRule WHERE Name LIKE '%{solutionCode}%'", False).AsEnumerable().Select(Function(lambda) lambda.item("Name").tostring()).tolist()
For Each brName As String In businessRulesList
Dim xfProjItem As New XFProjectItem(xfprojectitemtype.BusinessRule,"",brName,True)
xfprojObj.ProjectItems.Add(xfProjItem)
Next brName
'Dashboard Maintenance unit
Dim dashboardMaintUnitList As New List(Of String) From {$"OpenPlace Template ({solutionCode})"}
For Each dsMaintUnit As String In dashboardMaintUnitList
Dim xfProjItem As New XFProjectItem(xfprojectitemtype.DashboardMaintenanceUnit,"",dsMaintUnit,True)
xfprojObj.ProjectItems.Add(xfProjItem)
Next dsMaintUnit
'Dashboard Profile
Dim dashboardProfilesList As New List(Of String) From {$"OpenPlace Template ({solutionCode})"}
For Each dsProfile As String In dashboardProfilesList
Dim xfProjItem As New XFProjectItem(xfprojectitemtype.DashboardProfile,"",dsProfile,True)
xfprojObj.ProjectItems.Add(xfProjItem)
Next dsProfile
'Data Management Jobs
Dim dmGroupsList As New List(Of String) From {$"Export Solution ({solutionCode})"}
For Each dmGroup As String In dmGroupsList
Dim xfProjItem As New XFProjectItem(xfprojectitemtype.DataManagementGroup,"",dmGroup,True)
xfprojObj.ProjectItems.Add(xfProjItem)
Next dmGroup
'Process the export
Dim zipByte As Byte() = XfProjectWcf.ExtractXFProjectZipFile(dbconnfw,dbconnApp,xfprojObj)
Dim targetFileInfo As New XFFileInfo(filesystemlocation.ApplicationDatabase,path.Combine("Documents","Users",stringhelper.RemoveSystemCharacters(si.UserName,False,False),xfprojObj.DefaultZipFileName & ".zip"))
Dim targetFile As New XFFile(targetFileInfo,String.Empty,zipByte)
brapi.FileSystem.InsertOrUpdateFile(si, targetFile)
'Extract the xfProject xml file
Dim targetXFProjInfo As New XFFileInfo(filesystemlocation.ApplicationDatabase,path.Combine("Documents","Users",stringhelper.RemoveSystemCharacters(si.UserName,False,False),xfprojObj.DefaultZipFileName & ".xfproj"))
Dim targetXFProjFile As New XFFile(targetXFProjInfo,String.Empty,xfprojObj.WriteXmlStringAsBytes(si))
brapi.FileSystem.InsertOrUpdateFile(si, targetXFProjFile)
End Using
End Using
03-25-2024 12:56 PM
In your example, what is the "solutionCode"? I looks like it is a Parameter called HelpAboutSolutionCode_AMGH.
what is {$"OpenPlace Template ({solutionCode})"} and $"Export Solution ({solutionCode})"}
03-25-2024 01:03 PM - edited 03-25-2024 01:07 PM
SolutionCode is a three letter designation that is stored in a Literal Parameter, specific to the solution.
You can omit it in the code if you're not using a Solution Code. Omitting it will simply bring back everything in your application, instead of things specific to a solution.
08-05-2024 08:10 PM
Hey Robb, could you please help me with how to extract specific objects from an application? For example, if I wanted to extract a certain dashboard parameter how would I do this through a business rule. My goal is to apply this to a number of different types of objects in OneStream.
03-25-2024 11:43 AM - edited 03-25-2024 11:49 AM
You would use the XmlLoadWcf library for this. It can load either xml as a string or as a zip file. It runs similar to running a Data Management sequence, returning a TaskActivity object:
Dim task As TaskActivityItem = Nothing
'Execute the XML load and assign the TaskActivityItem
task = XmlLoadWcf.StartLoadXml(si, xmlString, Nothing, String.Empty, SystemXmlFileType.Unknown, ApplicationXmlFileType.ApplicationDashboards, Nothing)
Here it is an example round trip using some of @PeterFu's code:
Dim configSettings as AppServerConfigSettings = AppServerConfig.GetSettings(si)
Dim folderPath as String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, True, configSettings.FileShareRootFolder, si.AppToken.AppName) & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\MetadataExtracts"
if Not Directory.Exists(folderPath) then Directory.CreateDirectory(folderPath)
Dim filePath as String = folderPath & "\" & si.AppToken.AppName & ".zip"
If File.Exists(filePath) Then File.Delete(filePath)
'Set the extract options
Dim xmlOptions as New XmlExtractOptions
xmlOptions.ExtractAllItems = True
'Execute the Metadata Extract
Using dbConnFW as DBConnInfo = BRAPi.Database.CreateFrameworkDbConnInfo(si)
Using dbConnApp as DBConnInfo = BRAPi.Database.CreateApplicationDbConnInfo(si)
Dim zipBytes as Byte() = ApplicationZipFileHelper.Extract(dbConnFW, dbConnApp, Nothing, xmlOptions)
'Append the contents of this workflow profile to the extract file
Using FS As New FileStream(filePath, FileMode.Append, FileAccess.Write)
'Create a binary writer, and write all bytes to the FileStream at once
Using BW As New BinaryWriter(FS)
BW.Write(zipBytes)
End Using
End Using
End Using
End Using
'Load the file back in
Dim task As TaskActivityItem = Nothing
'load the application zip file
task = XmlLoadWcf.StartLoadXml(si, "", Nothing, filePath, SystemXmlFileType.Unknown, ApplicationXmlFileType.ApplicationZipFile, Nothing)