Create Customer Journal Lines (8611) report

CraineGACraineGA Member Posts: 28
edited 2011-03-22 in NAV Three Tier
Trying to automate the process of creating customer journals for data migration of customer outstanding balances from a legacy system. Have successfully developed a codeunit that replicates the function of report 8611 that works fine when executed within NAV object designer. However, when the codeunit is exposed as web service and executed within VS2010, I receive the following error:-

There is no Currency Exchange Rate within the filter. Filters: Currency Code: USD, Starting Date: ''..''

Can't understand why execution of CU in NAV is ok but fails web service is invoked? Any ideas?

Here is the code
OnRun()

PostingDate := WORKDATE;
DocumentDate := PostingDate;
DocumentTypes := DocumentTypes::Invoice;
JournalTemplate := 'GENERAL';
BatchName := 'DEFAULT';
TemplateCode := 'DTRTAKEON';
CreateLine(JournalTemplate, BatchName, TemplateCode);

GetStandardJournalLine() : Boolean
IF TemplateCode = '' THEN
  EXIT(FALSE);
StdGenJounalLine.SETRANGE("Journal Template Name",StdGenJournal."Journal Template Name");
StdGenJounalLine.SETRANGE("Standard Journal Code",StdGenJournal.Code);
EXIT(StdGenJounalLine.FIND('-'))

CopyStdGenJnlLineDims(StdGenJnlLine1 : Record "Standard General Journal Line";GenJnlLine1 : Record "Gen. Journal Line")
JnlLineDimFrom.SETRANGE("Table ID",DATABASE::"Standard General Journal Line");
JnlLineDimFrom.SETRANGE("Journal Template Name",StdGenJnlLine1."Journal Template Name");
JnlLineDimFrom.SETRANGE("Journal Batch Name",StdGenJnlLine1."Standard Journal Code");
JnlLineDimFrom.SETRANGE("Journal Line No.",StdGenJnlLine1."Line No.");

DimMgt.DeleteJnlLineDim(DATABASE::"Gen. Journal Line",GenJnlLine1."Journal Template Name",
  GenJnlLine1."Journal Batch Name",GenJnlLine1."Line No.",0);

DimMgt.MoveJnlLineDimToJnlLineDim(JnlLineDimFrom,DATABASE::"Gen. Journal Line",
  GenJnlLine1."Journal Template Name",GenJnlLine1."Journal Batch Name",GenJnlLine1."Line No.");

CreateLine(JournalTemplate : Text[10];BatchName : Code[20];TemplateCode : Code[20])
Customer.SETFILTER(Customer."No.", '<>01121212');

IF Customer.FINDSET(FALSE , FALSE) THEN
REPEAT
  
//created from OnPreDataItem
IF JournalTemplate = '' THEN
  ERROR(Text001);

IF BatchName = '' THEN
  ERROR(Text002);

IF TemplateCode = '' THEN
  ERROR(Text003);

GenJnlLine.SETRANGE("Journal Template Name",JournalTemplate);
GenJnlLine.SETRANGE("Journal Batch Name",BatchName);
IF GenJnlLine.FIND('+') THEN
  LineNo := GenJnlLine."Line No." + 10000
ELSE
  LineNo := 10000;

GenJnlBatch.GET(JournalTemplate,BatchName);
StdGenJournal.GET(JournalTemplate,TemplateCode);
//created from OnAferGetRecord
GenJnlLine.INIT;
IF GetStandardJournalLine THEN BEGIN
GenJnlLine."Journal Template Name" := StdGenJournal."Journal Template Name";
GenJnlLine."Journal Batch Name" := GenJnlBatch.Name;
GenJnlLine.SETRANGE("Journal Template Name",StdGenJournal."Journal Template Name");
GenJnlLine.SETRANGE("Journal Batch Name",GenJnlBatch.Name);

LastGenJnlLine.SETRANGE("Journal Template Name",StdGenJournal."Journal Template Name");
LastGenJnlLine.SETRANGE("Journal Batch Name",GenJnlBatch.Name);

IF LastGenJnlLine.FIND('+') THEN;

GenJnlBatch.SETRANGE("Journal Template Name",StdGenJournal."Journal Template Name");
GenJnlBatch.SETRANGE(Name,GenJnlBatch.Name);

IF GenJnlBatch.FIND('-') THEN;


  StdGenJournalLine.SETRANGE("Journal Template Name",StdGenJournal."Journal Template Name");
  StdGenJournalLine.SETRANGE("Standard Journal Code",StdGenJournal.Code);
  IF StdGenJournalLine.FIND('-') THEN
    REPEAT
GenJnlLine.INIT;
GenJnlLine."Line No." := 0;
GenJnlManagement.CalcBalance(GenJnlLine,LastGenJnlLine,Balance,TotalBalance,ShowBalance,ShowTotalBalance);
GenJnlLine.SetUpNewLine(LastGenJnlLine,Balance,TRUE);
IF LastGenJnlLine."Line No." <> 0 THEN
  GenJnlLine."Line No." := LastGenJnlLine."Line No." + 10000
ELSE
  GenJnlLine."Line No." := 10000;

GenJnlLine.TRANSFERFIELDS(StdGenJournalLine,FALSE);
GenJnlLine.UpdateLineBalance;
GenJnlLine.VALIDATE("Currency Code");

IF GenJnlLine."VAT Prod. Posting Group" <> '' THEN
  GenJnlLine.VALIDATE("VAT Prod. Posting Group");
IF (GenJnlLine."VAT %" <> 0) AND GenJnlBatch."Allow VAT Difference" THEN
  GenJnlLine.VALIDATE("VAT Amount",StdGenJournalLine."VAT Amount");
GenJnlLine.VALIDATE(GenJnlLine."Bal. VAT Prod. Posting Group");

IF GenJnlBatch."Allow VAT Difference" THEN
  GenJnlLine.VALIDATE("Bal. VAT Amount",StdGenJournalLine."Bal. VAT Amount");
GenJnlLine.INSERT(TRUE);

CopyStdGenJnlLineDims(StdGenJournalLine,GenJnlLine);

LastGenJnlLine := GenJnlLine;
      IF PostingDate <> 0D THEN
        GenJnlLine.VALIDATE("Posting Date",PostingDate);

      GenJnlLine.VALIDATE("Document Type",DocumentTypes);
      GenJnlLine.VALIDATE("Account Type",GenJnlLine."Account Type"::Customer);
      GenJnlLine.VALIDATE("Account No.",Customer."No.");
      IF (GenJnlBatch."Bal. Account Type" = GenJnlBatch."Bal. Account Type"::"G/L Account") AND
         (GenJnlBatch."Bal. Account No." <> '') THEN BEGIN
          GenJnlLine.VALIDATE("Bal. Account Type",GenJnlLine."Bal. Account Type"::"G/L Account");
          GenJnlLine.VALIDATE("Bal. Account No.",GenJnlBatch."Bal. Account No.");
      END ELSE
      IF Customer."Customer Posting Group" <> '' THEN
        IF CustPostGrp.GET(Customer."Customer Posting Group") THEN BEGIN
          GenJnlLine.VALIDATE("Bal. Account Type",GenJnlLine."Bal. Account Type"::"G/L Account");
          GenJnlLine.VALIDATE("Bal. Account No.",CustPostGrp."Receivables Account");
        END;

      IF DocumentDate <> 0D THEN BEGIN
        GenJnlLine.VALIDATE("Posting Date",DocumentDate);
        GenJnlLine."Posting Date" := PostingDate;
      END;

      GenJnlLine.MODIFY(TRUE);
    UNTIL StdGenJournalLine.NEXT = 0;
END ELSE BEGIN
  GenJnlLine.VALIDATE("Journal Template Name",GenJnlLine.GETFILTER("Journal Template Name"));
  GenJnlLine.VALIDATE("Journal Batch Name",BatchName);
  GenJnlLine."Line No." := LineNo;
  LineNo := LineNo + 10000;

  IF PostingDate <> 0D THEN
    GenJnlLine.VALIDATE("Posting Date",PostingDate);

  GenJnlLine.VALIDATE("Document Type",DocumentTypes);
  GenJnlLine.VALIDATE("Account Type",GenJnlLine."Account Type"::Customer);
  GenJnlLine.VALIDATE("Account No.",Customer."No.");
  IF (GenJnlBatch."Bal. Account Type" = GenJnlBatch."Bal. Account Type"::"G/L Account") AND
    (GenJnlBatch."Bal. Account No." <> '') THEN BEGIN
    GenJnlLine.VALIDATE("Bal. Account Type",GenJnlLine."Bal. Account Type"::"G/L Account");
    GenJnlLine.VALIDATE("Bal. Account No.",GenJnlBatch."Bal. Account No.");
  END ELSE
  IF Customer."Customer Posting Group" <> '' THEN
    IF CustPostGrp.GET(Customer."Customer Posting Group") THEN BEGIN
      GenJnlLine.VALIDATE("Bal. Account Type",GenJnlLine."Bal. Account Type"::"G/L Account");
      GenJnlLine.VALIDATE("Bal. Account No.",CustPostGrp."Receivables Account");
    END;
  IF DocumentDate <> 0D THEN BEGIN
    GenJnlLine.VALIDATE("Posting Date",DocumentDate);
    GenJnlLine."Posting Date" := PostingDate;
  END;

  IF NOT GenJnlLine.INSERT(TRUE) THEN
    GenJnlLine.MODIFY(TRUE);
END;
  

UNTIL Customer.NEXT = 0;
Kind Regards

Comments

  • abhinav0408abhinav0408 Member Posts: 35
    Your seems that you havn't specified the exchange rate of your currency code.
    just simply go to currency setup and check your currency code "USD" has its defined Exchange rate
  • deV.chdeV.ch Member Posts: 543
    Looks like your posting date is empty...

    I recently noticed the same problem in a standard report, the problem was that OnValidate() of Account No. searches for exchange rates within the posting date, but the posting date was emtpy because it was not filled at this time. Maybe it's a bug in the standard...

    Code was like this:
    GenJnlLine.VALIDATE("Account No.",GLAccSettle."No.");
    GenJnlLine."Posting Date" := PostingDate;
    

    I changed to this:
    GenJnlLine."Posting Date" := PostingDate;
    GenJnlLine.VALIDATE("Account No.",GLAccSettle."No.");
    
Sign In or Register to comment.