How to selec a folder in WEBCLIENT in Navision.

kovaidonkovaidon Member Posts: 55
Hi all,

I case of RTC , we have function in Codeunit -419(File Management) "SelectFolderDialog", Which is useful and can be used to select folder.

But in case of WEBCLIENT, this SELCTFOLDERDIALOG is not working.is there is any alternative.?

Please experts expecting your valuable suggestion

Best Answer

  • ftorneroftornero Member Posts: 524
    Answer ✓
    Hello @kovaidon,

    Looks like the DotNet Folder Dialog doesn't work, so I did a workaround borrowing some functions from the codeunit 419 of BC.
    OBJECT Codeunit 50997 Folder Mgt.
    {
      OBJECT-PROPERTIES
      {
        Date=15-10-18;
        Time=23:43:21;
        Modified=Yes;
        Version List=DIR;
      }
      PROPERTIES
      {
        OnRun=BEGIN
              END;
    
      }
      CODE
      {
        VAR
          ServerFileHelper@1000000003 : DotNet "'mscorlib'.System.IO.File";
          ServerDirectoryHelper@1000000002 : DotNet "'mscorlib'.System.IO.Directory";
          PathHelper@1000000004 : DotNet "'mscorlib'.System.IO.Path";
    
        PROCEDURE GetServerDirectoryListInclSubDirs@1000000002(VAR TempNameValueBuffer@1000 : TEMPORARY Record 823;DirectoryPath@1001 : Text);
        BEGIN
          TempNameValueBuffer.RESET;
          TempNameValueBuffer.DELETEALL;
    
          GetServerDirectoryListInclSubDirsInner(TempNameValueBuffer,DirectoryPath);
        END;
    
        LOCAL PROCEDURE GetServerDirectoryListInclSubDirsInner@1000000001(VAR NameValueBuffer@1000 : Record 823;DirectoryPath@1001 : Text);
        VAR
          ArrayHelper@1002 : DotNet "'mscorlib'.System.Array";
          FileSystemEntry@1004 : Text;
          Index@1003 : Integer;
          LastId@1005 : Integer;
        BEGIN
          ArrayHelper := ServerDirectoryHelper.GetDirectories(DirectoryPath);
          FOR Index := 1 TO ArrayHelper.GetLength(0) DO BEGIN
            IF NameValueBuffer.FINDLAST THEN
              LastId := NameValueBuffer.ID;
            EVALUATE(FileSystemEntry,ArrayHelper.GetValue(Index - 1));
            IF ServerDirectoryExists(FileSystemEntry) THEN
              NameValueBuffer.ID := LastId + 1;
              NameValueBuffer.Name := COPYSTR(FileSystemEntry,1,250);
              NameValueBuffer.Value := COPYSTR(GetFileNameWithoutExtension(NameValueBuffer.Name),1,250);
              NameValueBuffer.INSERT;
              GetServerDirectoryListInclSubDirsInner(NameValueBuffer,FileSystemEntry)
          END;
        END;
    
        PROCEDURE ServerDirectoryExists@48(DirectoryPath@1000 : Text) : Boolean;
        BEGIN
          EXIT(ServerDirectoryHelper.Exists(DirectoryPath));
        END;
    
        PROCEDURE GetFileNameWithoutExtension@35(FilePath@1000 : Text) : Text;
        BEGIN
          EXIT(PathHelper.GetFileNameWithoutExtension(FilePath));
        END;
    
        BEGIN
        END.
      }
    }
    

    You can call the function like this:
    FolderMgt.GetServerDirectoryListInclSubDirs(Buffer, 'C:\NAV09R2(32794)');
    PAGE.RUN(823, Buffer);
    

    There FolderMgt and Buffer (temporary) are:
    Name	DataType	Subtype
    FolderMgt	Codeunit	Folder Mgt.	
    Buffer	Record	Name/Value Buffer	
    

    You need to provide a path to the function, an improve would be first show the logical units in the server an after choosing one show the folders.

    Also you need to elaborate the call to the PAGE 823 to get the folder chosen.

    Regards.

Answers

  • kovaidonkovaidon Member Posts: 55
    Mr. ftornero! Could you please help me out in this?
  • ftorneroftornero Member Posts: 524
    Hello @kovaidon,

    Could you elaborate a little ?

    - NAV version or it's BC
    - on-premise
    - cloud, etc.

    And what do you want to achieve by selecting a folder ?

    Regards.
  • kovaidonkovaidon Member Posts: 55
    Hi sir,

    it is for Updating Setup -Path Selection in Web Client environment.

  • ftorneroftornero Member Posts: 524
    Well, the problem with the "SelectFolderDialog" function in the codeunit 419 is that uses the DotNet vars to run on Client, and in the Web client you can not use this vars, but you can use DotNet vars that run on Sever.

    So, if the folder to select is accesible form the server you can borrow that function ,copy to one of your codeunits and change the DotNet vars to run on Server.

    yc8qxbsbwtbe.png

    Regards.
  • kovaidonkovaidon Member Posts: 55
    Hi sir,

    I have even tried with by setting Properties of RunOnClient- No(Which Run in Server). but it is not working, since the DOTNET Variable defined are Windows based .
    Do we have option other than developing Java Script based Conteol addins for this?
  • ftorneroftornero Member Posts: 524
    You can use DotNET vars in the server.

    Could you tell what version of NAV are you using ?
  • kovaidonkovaidon Member Posts: 55
    Hi,

    Iam using NAv2017 Version.



  • ftorneroftornero Member Posts: 524
    Hello @BlackTiger ,

    I previously said that the server have to have access to the folder (a shared one).

    To @kovaidon, I going to do some test
  • ftorneroftornero Member Posts: 524
    Well, this the error when calling the "SelectFolderDialog" on the server with the web client

    luxycp3qgpum.png


    I'm going to try other options and keep you posted.

    Regards.
  • kovaidonkovaidon Member Posts: 55
    Hi sir,

    Exactly same error.

    Looking forward for your valuble input .

  • ftorneroftornero Member Posts: 524
    Answer ✓
    Hello @kovaidon,

    Looks like the DotNet Folder Dialog doesn't work, so I did a workaround borrowing some functions from the codeunit 419 of BC.
    OBJECT Codeunit 50997 Folder Mgt.
    {
      OBJECT-PROPERTIES
      {
        Date=15-10-18;
        Time=23:43:21;
        Modified=Yes;
        Version List=DIR;
      }
      PROPERTIES
      {
        OnRun=BEGIN
              END;
    
      }
      CODE
      {
        VAR
          ServerFileHelper@1000000003 : DotNet "'mscorlib'.System.IO.File";
          ServerDirectoryHelper@1000000002 : DotNet "'mscorlib'.System.IO.Directory";
          PathHelper@1000000004 : DotNet "'mscorlib'.System.IO.Path";
    
        PROCEDURE GetServerDirectoryListInclSubDirs@1000000002(VAR TempNameValueBuffer@1000 : TEMPORARY Record 823;DirectoryPath@1001 : Text);
        BEGIN
          TempNameValueBuffer.RESET;
          TempNameValueBuffer.DELETEALL;
    
          GetServerDirectoryListInclSubDirsInner(TempNameValueBuffer,DirectoryPath);
        END;
    
        LOCAL PROCEDURE GetServerDirectoryListInclSubDirsInner@1000000001(VAR NameValueBuffer@1000 : Record 823;DirectoryPath@1001 : Text);
        VAR
          ArrayHelper@1002 : DotNet "'mscorlib'.System.Array";
          FileSystemEntry@1004 : Text;
          Index@1003 : Integer;
          LastId@1005 : Integer;
        BEGIN
          ArrayHelper := ServerDirectoryHelper.GetDirectories(DirectoryPath);
          FOR Index := 1 TO ArrayHelper.GetLength(0) DO BEGIN
            IF NameValueBuffer.FINDLAST THEN
              LastId := NameValueBuffer.ID;
            EVALUATE(FileSystemEntry,ArrayHelper.GetValue(Index - 1));
            IF ServerDirectoryExists(FileSystemEntry) THEN
              NameValueBuffer.ID := LastId + 1;
              NameValueBuffer.Name := COPYSTR(FileSystemEntry,1,250);
              NameValueBuffer.Value := COPYSTR(GetFileNameWithoutExtension(NameValueBuffer.Name),1,250);
              NameValueBuffer.INSERT;
              GetServerDirectoryListInclSubDirsInner(NameValueBuffer,FileSystemEntry)
          END;
        END;
    
        PROCEDURE ServerDirectoryExists@48(DirectoryPath@1000 : Text) : Boolean;
        BEGIN
          EXIT(ServerDirectoryHelper.Exists(DirectoryPath));
        END;
    
        PROCEDURE GetFileNameWithoutExtension@35(FilePath@1000 : Text) : Text;
        BEGIN
          EXIT(PathHelper.GetFileNameWithoutExtension(FilePath));
        END;
    
        BEGIN
        END.
      }
    }
    

    You can call the function like this:
    FolderMgt.GetServerDirectoryListInclSubDirs(Buffer, 'C:\NAV09R2(32794)');
    PAGE.RUN(823, Buffer);
    

    There FolderMgt and Buffer (temporary) are:
    Name	DataType	Subtype
    FolderMgt	Codeunit	Folder Mgt.	
    Buffer	Record	Name/Value Buffer	
    

    You need to provide a path to the function, an improve would be first show the logical units in the server an after choosing one show the folders.

    Also you need to elaborate the call to the PAGE 823 to get the folder chosen.

    Regards.
  • kovaidonkovaidon Member Posts: 55
    edited 2018-10-16
    Sir Fernando,

    It works like Charms!. Please accept my Heartiest Thanks for your wonderful and Awesome Logic in bring out the output within limitations .

    Once again Thank you very much ! Hatsoff to you Sir!!!!
  • kovaidonkovaidon Member Posts: 55
    BlackTiger wrote: »
    Have you tested your code in Web Client?

    Yes. it works Sir!,
Sign In or Register to comment.