How to export/import processes from command line?

I would like to source control all the processes (OneIM v9.2)

There is of course the GUI option:
How to export processes (4328025)

Although this is a nice feature i would like to do this from the command line (scripted bulk export of all processes)
But as far as I'm aware, there is no option to do so.
If so has this ever been requested for future enhancement?

Thank you,
Niels

Parents Reply Children
  • I think there is no existing RFE with these requirements. At least I haven't found one.

    A poor man's workaround would be to export all process chains with the transporter and create a transport template doing this. Later on, you can use the command line transporter to export the processes using the templates. The downside, any new process needs to be manually added to the templates XML.

    Maybe someone else has a better idea.

  • There is still no ootb solution or tool for it.

    Out of curiosity, I wrote some scripts (DialogScript) that allow you to export process chains (single or bulk) in the XML format used by Designer.

    #If Not SCRIPTDEBUGGER Then
            Imports System.Xml
            Imports VI.DB.Sync
    #End If
            Public Sub SDK_JobChain_BulkXMLExport(ByVal strDirectory As String, ByVal strFilterOption As String)
                ' Handle strDirectory
                If String.IsNullOrWhiteSpace(strDirectory) Then
                    Throw New ArgumentNullException(NameOf(strDirectory), "No directory specified.")
                End If
    
                ' Handle strFilterOptions
                If String.IsNullOrWhiteSpace(strFilterOption) Then
                    Throw New ArgumentNullException(NameOf(strFilterOption), "No filter options specified.")
                End If
    
                Dim validFilterOptions() As String = {"All", "Customized", "Custom"}
                If Not validFilterOptions.Contains(strFilterOption, StringComparer.InvariantCultureIgnoreCase) Then
                    Throw New ArgumentOutOfRangeException(NameOf(strFilterOption), "Valid filter options are 'All', 'Customized', 'Custom'.")
                End If
    
                Dim strWhereClause As String = Nothing
                Dim dbQuery As Query = Nothing
    
                Select Case strFilterOption.ToUpperInvariant
                    Case "ALL"
                        strWhereClause = "1=1"
                        dbQuery = Query.From(Table.JobChain).Where(strWhereClause).SelectAll
                    Case "CUSTOMIZED"
                        ' Similar condition as used in the Designer to identify the ootb processes that have been modified
                        strWhereClause =
                            "dbo.QBM_FCVGUIDToModuleOwner(UID_JobChain) <> (Select ModuleOwner from DialogDatabase where IsMainDatabase=1)
                            And ( 
                                exists(select 1 
                                            From QBMBufferConfig b Join JobChain c on b.ObjectKeyOfRow = c.XObjectKey
                                            Where c.UID_JobChain = JobChain.UID_JobChain
                                            And b.TableName = 'JobChain'
                                            )
                                Or exists (select 1 
                                            From QBMBufferConfig b Join Job j on b.ObjectKeyOfRow = j.XObjectKey
                                            Where j.UID_JobChain = JobChain.UID_JobChain
                                            And b.TableName = 'Job'
                                            )
                                Or exists (select 1 
                                            From QBMBufferConfig b Join JobEventGen e on b.ObjectKeyOfRow = e.XObjectKey
                                            Where e.UID_JobChain = JobChain.UID_JobChain
                                            And b.TableName = 'JobEventGen'
                                            )
                                Or exists (select 1 
                                            From QBMBufferConfig b Join JobRunParameter rp on b.ObjectKeyOfRow = rp.XObjectKey
                                                                    Join Job j on rp.UID_Job = j.UID_Job
                                            Where j.UID_JobChain = JobChain.UID_JobChain
                                            And b.TableName = 'JobRunParameter'
                                            )
                            )"
                        dbQuery = Query.From(Table.JobChain).Where(strWhereClause).SelectAll
                    Case "CUSTOM"
                        ' Condition to select all custom processes
                        dbQuery = Query.From(Table.JobChain).Where(Function(c) c.Column(Table.JobChain.UID_JobChain).StartsWith("CCC")).SelectAll
                End Select
    
                ' Fetch process from database
                Dim dbCol As IEntityCollection = Session.Source.GetCollection(dbQuery, EntityCollectionLoadType.BulkReadOnly)
                Dim strfilename As String = String.Empty
    
                ' Export each process as XML
                For Each eJobchain In dbCol
                    strfilename = Path.Combine(strDirectory, String.Concat(VID_FormatAndRemoveSpecialCharacters(eJobchain.GetValue(Of String)(Table.JobChain.Name)), ".xml"))
                    Dim doc As XmlDocument = GetJobChainXML(eJobchain)
                    doc.Save(strfilename)
                Next
            End Sub
            Public Sub SDK_JobChain_SingleXMLExport(ByVal strDirectory As String, xJobChain As String)
                ' Handle strDirectory
                If String.IsNullOrWhiteSpace(strDirectory) Then
                    Throw New ArgumentNullException(NameOf(strDirectory), "No directory specified.")
                End If
    
                If String.IsNullOrWhiteSpace(xJobChain) Then
                    Throw New ArgumentNullException(NameOf(xJobChain), "No process specified.")
                End If
    
                Dim eJobChain As IEntity = Session.Source.Get(New DbObjectKey(xJobChain))
                Dim strfilename As String = Path.Combine(strDirectory, String.Concat(VID_FormatAndRemoveSpecialCharacters(eJobChain.GetValue(Of String)(Table.JobChain.Name)), ".xml"))
                Dim doc As XmlDocument = GetJobChainXML(eJobChain)
                doc.Save(strfilename)
            End Sub
    
            Private Function GetJobChainXML(ByRef eJobChain As IEntity) As XmlDocument
                If eJobChain Is Nothing Then Throw New ArgumentNullException("eJobChain")
                Dim entityGraph = eJobChain.CollectGraph(Session, "JobEventGen.UID_JobChain", "JobChain.UID_Job", "Job.UID_SuccessJob", "Job.UID_ErrorJob", "JobRunParameter.UID_Job", "JobEventGen.UID_QBMEvent")
                Dim entityDataArray = entityGraph.ToEntityData(Session)
                Dim doc = New XmlDocument()
                doc.LoadXmlSafe(entityDataArray.ToXml(False))
                Return doc
            End Function
    
    #If Not SCRIPTDEBUGGER Then
            References JobChainCopy.dll
            Imports VI.DB.Entities.Transport
    #End If
            Public Sub SDK_JobChain_SingleXMLImport(ByVal strFileName As String)
                Dim apkJobChain As AlternateDbObjectKey = Nothing
    
                Using dbTransaction As Transaction = New Transaction(Connection)
                    Dim xmlDoc As XmlDocument = New XmlDocument()
                    xmlDoc.LoadSafe(strFileName)
                    Dim data As EntityData() = XmlTransportSerialization.GraphFromXml(xmlDoc.DocumentElement)
                    Dim chainData = data.FirstOrDefault(Function(d) String.Equals(d.Key.Table, "JOBCHAIN", StringComparison.OrdinalIgnoreCase))
    
                    If chainData IsNot Nothing Then
                        apkJobChain = New AlternateDbObjectKey(chainData.Key)
                        Dim existing As IEntity = Nothing
    
                        If Session.Source().TryGet(apkJobChain, EntityLoadType.[ReadOnly], existing) Then
                            Dim jcImport = New JobChainImport()
                            jcImport.DeleteJobChain(Connection, existing.GetValue(Of String)("Name"))
                        End If
                    End If
    
                    Dim entities = data.GetEntityGraph(Session)
                    entities.Save(Connection.Session)
                    dbTransaction.Commit()
                End Using
            End Sub
    

    To automate the export you can use IdentityManager.PoSh (https://github.com/OneIdentity/IdentityManager.PoSh/tree/master)

    IdentityManager.PoSh sample to export all custom processes

    Import-Module .\PSIdentityManagerUtils -Force
    $connectionString = "User ID=<DBUser-Name>;initial Catalog=<DB-Name>;Data Source=<Server-Name>;Password=<DBUser-Password>;pooling= 'false'"
    $authenticationString = 'Module=DialogUser;User=viadmin;Password=<Password>'
    New-IdentityManagerSession -ConnectionString $connectionString -AuthenticationString $authenticationString  -ModulesToAdd QBM
    Invoke-IdentityManagerScript -Name 'SDK_JobChain_BulkXMLExport' -Parameters @('D:\JobChains','CUSTOM')

    IMPORTANT NOTE:

    The import will only work if the Designer is installed in the directory where the script is executed. It needs the JobChainCopy.dll which is only installed if the Designer is installed.

  • Wow, thank you so much!
    Really appreciate it. Just tried it out very impressed 100Bangbang