Monday 8 July 2013

Downloading Files without user interaction in the NAV Role Tailored Client

Working with three tier means you can do File operations in only the Machine which has NAV Service.If you have to move files to the client machine then we go for Download or Streaming Procedure.
But here we have a limitation like user interaction is required.

This procedure works even for the Network Path too.(I mean three tiers installed in different machines environment,NAV 2007 R2 has issue in handling with Network paths.)

In order to escape  the interaction from user we have an option like VB Script.
We can use as following Script which runs a Report and save the generated file in the client location.

Sample Code:

Name          DataType        Subtype                                              Length
objScript       Automation   'Microsoft Script Control 1.0'.ScriptControl
CR                   Text                                                                                1

Report.SAVEASPDF(Number, TEMPORARYPATH+FileName [, Record]) //File location can be only                                                                                                                           service installed machine

IF CREATE(objScript,TRUE,TRUE) THEN
BEGIN
  CR := ' '; CR[1] := 13;
  objScript.Language := 'VBScript';
  objScript.AddCode(
  'function DownloadToClient(fromFile, FileName)'+CR+                     //DownloadToClient-is a User                                                                                                                                 defined function   
  'set fso = createobject("Scripting.FileSystemObject")'+CR+
  'set x = createobject("Scriptlet.TypeLib")'+CR+
  'path = fso.getfolder("'Required Client Location'")'+CR+
  'toPath = path'+CR+
  'fso.MoveFile fromFile, toPath+"\"+toFile'+CR+                                         
  'RenameTempFile = toPath'+CR+
  'end function');
   objScript.Eval('DownloadToClient("'+ClientFileName+'","'+ToFile+'")');  //executing above created function
  END;
                                                                                                       

No comments:

Post a Comment