Autoimport fob objects

fcrespofcrespo Member Posts: 9
edited 2015-06-30 in NAV Tips & Tricks
The company I'm working has more than 100 shops using Navision SQL client on localhost. We use MSMQ and Webservices to get online sales info but updates on Navision databases are very hard because we have to connect them through VNC clients and import fob objects manually.

Finally I get the solution to autoimport fob objects using a NAS, CFront and FTP. The NAS checks a folder where fob objects are uploaded and when detects a new fob file autoimports it using CFront.

I've found lots of solutions like CSideIntegration Utilities (http://www.mibuso.com/forum/viewtopic.php?f=7&t=44886&start=0) but all them needs a Navision session opened and import objects as text. Of course using NAS we are using a session, but we don't care if the user closes his Navision session.

If the import process fail, we can get the result of the CFront Error Message through a MSMQ sent via WebService.

If someone is interested I can share the solution.
Felipe Crespo

Comments

  • alok_kulalok_kul Member Posts: 8
    Yes,Please
  • fcrespofcrespo Member Posts: 9
    edited 2012-01-04
    PRERREQUISITES
    ==============

    - Microsoft Dynamic Nav 5.0 SP1
    - Navision Application Server 5.0 SP1
    - C/Front 5.0 SP1
    - Navision Job Queue Module*
    - Automation library to interop with C/Front from C/AL**

    * Navision Job Queue Module is not necesary but smarter. NAS and a timer is enough.
    ** I developed a simple c# wrapper (FobTool.dll). I can mail if needed.


    HOWTO
    ======

    I created a codeunit with functions to be called from one Task Queue Entry (CU 50000 - Task Queue Management). The main function (ImportFob) checks a directory looking for new *.fob files. If one fob file is detected it connects to CFront and call to CFront function ImportFob(). After import the file is moved to a directory for processed files, if any error occurs it will be moved to another directory.

    Task Queue Entry throws ImportFob function every day and captures the success message or error message. I use a WebService to send a message if any error occurs (Implemented in Navision Task Queue module).


    SAMPLE CODES
    ============

    - C# Wrapper
    ============
            public bool ImportFob(String importPath, String importMode)
            {
    
                NavisionImportMode ImportMode;
                switch (importMode)
                {
                    case "Overwrite":
                        ImportMode = NavisionImportMode.Overwrite;
                        break;
                    case "Skip":
                        ImportMode = NavisionImportMode.Skip;
                        break;
                    case "ThrowError":
                        ImportMode = NavisionImportMode.ThrowError;
                        break;
                    default:
                        ImportMode = NavisionImportMode.Overwrite;
                        break;
                }
    
                try
                {
                    CFrontDotNet.Instance.ImportFOB(importPath, ImportMode);
                }
                catch (Exception e)
                {
                    this.SetErrorMsg(e.Message);
                    this.Disconnect();
                    return false;
                }
                return true;
    	}
    

    - ImportFob C/AL Function
    =========================
    	IF ISCLEAR(gFobAuto) THEN
    	  CREATE(gFobAuto);
    
    	MESSAGE('[NASFobImport] Buscando fobs en %1', gTPVSetup."Fobs Path");
    
    	CLEAR(lExplorer);
    
    	lExplorer.RESET;
    	lExplorer.SETRANGE(Path, gTPVSetup."Fobs Path");
    	lExplorer.SETRANGE("Is a file",TRUE);
    	IF lExplorer.FINDSET THEN BEGIN 
    	  lFobPath := lExplorer.Path + lExplorer.Name;
    	  IF FILE.EXISTS(lFobPath) THEN BEGIN
    
    		lImportedFileName := FORMAT(CURRENTDATETIME,0,'<Year,2><Month,2><Day,2><Hours24,2><Minutes,2><Seconds,2>') +
    						  '_' + lExplorer.Name;
    
    		lFobImportPath := gTPVSetup."Fobs Imported Path" + lImportedFileName;
    		lFobErrorPath := gTPVSetup."Fobs Error Path" + lImportedFileName;
    
    		MESSAGE('[NASFobImport] Procesando fichero %1', lExplorer.Path + lExplorer.Name);
    
    		// ############ CONEXIÓN #################
    		MESSAGE('[NASFobImport] Conectando a Navision [CFront]...');
    		lConRes := gFobAuto.Connect(gTPVSetup."FobTools Path",
    									'',
    									'',
    									gTPVSetup.Servername,
    									gTPVSetup."Navision Database",
    									COMPANYNAME,
    									TRUE,
    									'',
    									'');
    
    		IF lConRes THEN BEGIN
    		  MESSAGE('[NASFobImport] Conectado a Navision [CFront].')
    		END ELSE BEGIN
    		  ERROR('[NASFobImport] Error conectando a Navision [CFront]: %1', GetError());
    		END;
    
    		// ############ IMPORTACIÓN #################
    		MESSAGE('[NASFobImport] Importando fichero %1', lFobPath);
    		lImpRes :=  gFobAuto.ImportFob(lFobPath, 'Overwrite');
    
    		IF lImpRes THEN BEGIN
    		  IF FILE.EXISTS(lFobPath) THEN
    			FILE.RENAME(lFobPath,lFobImportPath);
    		  MESSAGE('[NASFobImport] Fichero %1 importado con éxito.', lFobPath);
    		END ELSE BEGIN
    		  IF FILE.EXISTS(lFobPath) THEN
    			FILE.RENAME(lFobPath,lFobErrorPath);
    		  ERROR('[NASFobImport] Error importando %1: %2',lFobPath,GetError());
    		END;
    		
    		// ############ DESCONEXIÓN #################
    		MESSAGE('[NASFobImport] Desconectando...');
    		lDiscRes := gFobAuto.Disconnect();
    
    		IF lDiscRes THEN BEGIN
    		  MESSAGE('[NASFobImport] Desconectado.')
    		END ELSE BEGIN
    		  ERROR('[NASFobImport] Error desconectando: %1',GetError());
    		END;
    
    		gMsg := STRSUBSTNO('[NASFobImport] Fichero %1 importado con éxito.', lFobPath);
    
    	  END;
    	END;
    




    It's necesary to change default paramater values to connect to a Native database.

    Thanks to ykerzreho for the request.

    Connect function parameters:

    netType values:
      "NativeNetB" "NativeSecureTcp" "NativeTcp" "SqlDefault" "SqlNamedPipe" "SqlTcpSocket" default value :"SqlDefault"

    driverType values
      "Native" "Sql" default value :"sql"
    Felipe Crespo
  • fcrespofcrespo Member Posts: 9
    Navision 5.0 SP1 is needed because C/Front only implements ImportFob() in this version.

    I detected some problems importing tables that contains fields used in SIFT tables (like Item Ledged Entry, G/L Entry,...)
    Felipe Crespo
  • beyrembeyrem Member Posts: 10
    Hello,

    Could you please share the objects.

    Thanks a lot
  • mohana_cse06mohana_cse06 Member Posts: 5,503
  • fcrespofcrespo Member Posts: 9
    edited 2011-11-24
    C/Front 5.00 SP1 is needed because is the only one that contains required functions.

    Link of wrapper library: http://dl.dropbox.com/u/24474654/FobTools.zip
    Felipe Crespo
  • beyrembeyrem Member Posts: 10
    Hello,

    I am using a NAV2009 SP1 classic.

    Thanks
  • fcrespofcrespo Member Posts: 9
    My solution allows import *.fob files. The blog one is for *.txt and the user have to compile objects manually...
    Felipe Crespo
  • selva1990selva1990 Member Posts: 25
    Hi fcrespo,

    The link given to download the object is not working. am in need of those objects. Can you share the Object ?
Sign In or Register to comment.