importing objects navision

navisionerinnavisionerin Member Posts: 161
Hello. I am creating a new database and importing new objects from text files. however i dont want to import them one by one.. is there a way to import them all at one go and if so how? currently i am copying and pasting them all in one .txt file so that i can import them together, but its still slowing me down..
any ideas?

Answers

  • aacnsilvaaacnsilva Member Posts: 23
    Hi @navisionerin,
    I use this and it works very well. https://mibuso.com/downloads/nav-object-splitter-v3.0.0.0
    With this tool you can split or join NAV txt files.
  • SanderDkSanderDk Member Posts: 502
    I have a couple of powershell script to do this:
    #Folder Settings
    $ObjFolder = 'C:\ObjectToImport\'
    $ArchivePath = 'C:\ObjectToImport\_done\'
    
    #Server settings
    $databaseName   = 'MyDatabase'
    $databaseServer = 'MyServer'
    $serverInstance = 'DynamicsNAV110'
    
    
    
    Import-Module 'C:\Program Files (x86)\Microsoft Dynamics NAV\110\RoleTailored Client\Microsoft.Dynamics.Nav.Model.Tools.psd1' -WarningAction SilentlyContinue | out-null
    Import-Module 'C:\Program Files\Microsoft Dynamics NAV\110\Service\NavAdminTool.ps1' -WarningAction SilentlyContinue | Out-Null
    
    
    $ErrorOccured = $false;
    $ErrorList = New-Object "System.Collections.Generic.List[String]"
    $Logpath = $ObjFolder + 'log\'
    Clear-Host
    foreach($file in Get-ChildItem $ObjFolder -Filter *.txt)
    {
        $filename = ($ObjFolder + $file.BaseName + '.txt')
        if(Test-Path $filename)
        {
            try
            {          
                Import-NAVApplicationObject -Path $filename -DatabaseName $databaseName -DatabaseServer $databaseServer -NavServerInstance $serverInstance -Confirm:$false -LogPath $Logpath
                if (( Get-ChildItem $Logpath | Measure-Object ).Count -eq 1)
                {
                    Move-Item -Path $filename -Destination ($ArchivePath + '\' + $file.BaseName + '.txt') -Confirm:$false
                }
                else
                {
                    $ErrorOccured = $true;
                }
            }
            Catch
            {
                $ErrorOccured = $true;
                $ErrorList.add($_.Exception.Message);
            }
            Finally
            {
                Remove-Item -Force -Path $Logpath -Recurse -Confirm:$false
            }
        }
    } 
    IF ($ErrorOccured)
    {
        Clear-Host
        Write-Host 'One or more error occured, please manuel import the remaining objects' -BackgroundColor Red
        if(!$ErrorList.Count -eq 0)
        {
            Write-Host 'Errors occured is as following:' -BackgroundColor Red
            foreach($e in $ErrorList)
            {
                Write-Host $e -BackgroundColor Red
            }
        }
    }
    else
    {
        Write-Host 'All objects imported' -BackgroundColor Green
    }
    
    For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.
Sign In or Register to comment.