Options

Adding Document Links Processing Report

Excepti0nalExcepti0nal Member Posts: 74
edited 2013-03-26 in NAV Three Tier
Hello,
We recently did an upgrade on our system from 4.0 to 2013. We had a processing report that would update links on ledger entries to our shared network drive (N:\ drive). Can anyone tell me why this code would no longer work in 2013? Also we used to be able to manually add the links. Now when you click links, it does not provide an option to add the links in the links box. Is there somewhere else that they need to be added?
APFileLocation := 'N:\Payables\';
ARFileLocation := 'N:\Receivables\';

OnPreReport()
IF GUIALLOWED THEN
  Window.OPEN('Processing  #####################################1#####');

APFileLocation := DELCHR(APFileLocation,'>','\') + '\';
ARFileLocation := DELCHR(ARFileLocation,'>','\') + '\';

MyFile.SETRANGE(Path,APFileLocation);
MyFile.SETRANGE("Is a file",TRUE);
IF MyFile.FIND('-') THEN REPEAT
    VendorLedger.RESET;
    VendorLedger.SETCURRENTKEY("Document No.");
    VendorLedger.SETRANGE("Document No.",COPYSTR(MyFile.Name,1,STRLEN(MyFile.Name)-4));
    VendorLedger.SETRANGE("Document Type",VendorLedger."Document Type"::Invoice);
    IF VendorLedger.FINDFIRST THEN BEGIN
      IF GUIALLOWED THEN
        Window.UPDATE(1,VendorLedger."Document No.");
      
      recordLink.SETRANGE(Description,MyFile.Name);
      IF recordLink.ISEMPTY THEN BEGIN
        VendorLedger.ADDLINK(MyFile.Path+MyFile.Name,MyFile.Name);
        COMMIT;
      END;
    END;
UNTIL MyFile.NEXT = 0;

MyFile.SETRANGE(Path,ARFileLocation);
MyFile.SETRANGE("Is a file",TRUE);
IF MyFile.FIND('-') THEN REPEAT
    CustLedger.RESET;
    CustLedger.SETCURRENTKEY("Document No.");
    CustLedger.SETRANGE("Document No.",COPYSTR(MyFile.Name,1,STRLEN(MyFile.Name)-4));
    CustLedger.SETRANGE("Document Type",VendorLedger."Document Type"::Invoice);
    IF CustLedger.FINDFIRST THEN BEGIN
      IF GUIALLOWED THEN
        Window.UPDATE(1,CustLedger."Document No.");
      recordLink.SETRANGE(Description,MyFile.Name);
      IF recordLink.ISEMPTY THEN BEGIN
        CustLedger.ADDLINK(MyFile.Path+MyFile.Name,MyFile.Name);
        COMMIT;
      END;
    
    END;
UNTIL MyFile.NEXT = 0;

IF GUIALLOWED THEN
  Window.CLOSE;

Answers

  • Options
    Excepti0nalExcepti0nal Member Posts: 74
    This issue was fixed with the code changes below. Thank you ara3n! Also to add new links to documents on the vendor ledger entry, it cannot be added from the links button on the ribbon. If you show the links factbox, you can add new links from there.
    OnInitReport()
    APFileLocation := 'N:\Payables\';
    ARFileLocation := 'N:\Receivables\';
    
    OnPreReport()
    IF GUIALLOWED THEN
      Window.OPEN('Processing #########################1#');
    
    APFileLocation := DELCHR(APFileLocation,'>','\') + '\';
    ARFileLocation := DELCHR(ARFileLocation,'>','\') + '\';
    
    
    VendorLedger.RESET;
    VendorLedger.SETCURRENTKEY("Document No.");
    VendorLedger.SETRANGE("Posting Date", CALCDATE('-5M',TODAY),TODAY);
    VendorLedger.SETRANGE("Document Type",VendorLedger."Document Type"::Invoice);
    IF VendorLedger.FINDSET  THEN REPEAT
     IF NOT VendorLedger.HASLINKS THEN BEGIN
        IF GUIALLOWED THEN
          Window.UPDATE(1,VendorLedger."Document No.");
        
        IF ClientFileHelper.Exists(APFileLocation + VendorLedger."Document No." + '.PDF') OR 
          ClientFileHelper.Exists(APFileLocation + VendorLedger."Document No." + '.pdf') THEN BEGIN
         VendorLedger.ADDLINK(APFileLocation + VendorLedger."Document No." + '.PDF'  ,VendorLedger."Document No." + '.PDF');
         COMMIT;
        END;
      END;
    UNTIL VendorLedger.NEXT = 0;
    
    
    
    CustLedger.RESET;
    CustLedger.SETCURRENTKEY("Document No.");
    CustLedger.SETRANGE("Posting Date", CALCDATE('-5M',TODAY),TODAY);
    CustLedger.SETRANGE("Document Type",CustLedger."Document Type"::Invoice);
    IF CustLedger.FINDFIRST THEN REPEAT
      IF NOT CustLedger.HASLINKS THEN BEGIN
        IF GUIALLOWED THEN
          Window.UPDATE(1,CustLedger."Document No.");
        
        IF ClientFileHelper.Exists(ARFileLocation + CustLedger."Document No." + '.PDF') OR
          ClientFileHelper.Exists(ARFileLocation + CustLedger."Document No." + '.pdf') THEN BEGIN
         CustLedger.ADDLINK(ARFileLocation + CustLedger."Document No." + '.PDF'  ,CustLedger."Document No." + '.PDF');
         COMMIT;
        END;
      END;
    UNTIL CustLedger.NEXT = 0;
    
    IF GUIALLOWED THEN
      Window.CLOSE;
    
    OnPostReport()
    
Sign In or Register to comment.