Hi,
I am trying to import data from a CSV file to AX 2012, using AIF, and consuming the Web Service through C# Web Application.
The data that I am trying to extract is from:
Date | Type of account | LedgerDimension MainAccount | LedgerDimension Display Value | LedgerDimension Dimension Values | Description at the Line | Debit amount | Credit amount | Currency | Offset account type | Offset MainAccount | Offset Account Display Value | Offset Account Values | Journal name | Description in the header | Company / Offset Company |
20/06/2012 | Bank | BANK001 | BANK001 | Test GL Upload | 0.00 | 100.00 | GBP | Cust | EPP000001 | EPP000001 | GENJNL | General Journal - testing | epp |
The code used in the Web application to consume the Web Services is (assume it is Parsing CSV file for string[] and ImportingHelper.EnumUtils.Parse is parsing to an enum type) :
public class ImportingJournals : ImportClass
{
internal static int TransDateIndex = 0;
internal static int AccountTypeIndex = 2;
internal static int LedgerDimensionMainAccountIndex = 3;
internal static int LedgerDimensionOnDisplayValueIndex = 4;
internal static int LedgerDimensionValuesIndex = 5;
internal static int DescriptionOnLineIndex = 6;
internal static int DebittIndex = 7;
internal static int CreditIndex = 8;
internal static int CurrencyIndex = 9;
internal static int OffsetAccountTypeIndex = 10;
internal static int OffsetMainAccountIndex = 11;
internal static int OffsetDisplayAccountIndex = 12;
internal static int OffsetAccountValuesIndex = 13;
internal static int JournalNameIndex = 14;
internal static int DescriptionHeaderIndex = 15;
internal static int CompanyIndex = 16;
internal static int OffsetCompanyIndex = 16;
internal static int FromCompanyIndex = 16;
internal static int ActiveIndex = 3;
internal static int ApproveIndex = 4;
internal static int FixedOffsetAccountIndex = 5;
internal static int ApprovalWorkflowIndex = 8;
internal static int DetailLevelIndex = 12;
internal static int FeesPostingIndex = 13;
internal static int LinesLimitIndex = 14;
internal static int PrivateForUserGroupIndex = 15;
internal static int VoucherSeriesIndex = 16;
internal static int NewVoucherIndex = 17;
internal static int NumberAllocationAtPostingIndex = 18;
internal static int DocumentIndex = 19;
internal static int FixedRateIndex = 20;
internal static int AmountIncludedSalesTaxIndex = 22;
internal static int HideSalesTaxFieldsInJournalEntryFormIndex = 23;
internal static int LanguageIndex = 27;
internal static int DescriptionTransIndex = 30;
public void CreateFromCSVFile()
{
throw new NotImplementedException();
}
public void CreateFromCSVFile(System.IO.Stream fileStream)
{
GeneralJournalServiceClient generalJournalServiceClient = new GeneralJournalServiceClient();
try
{
List<string[]> JournalData = Helper.ImportCSVFile.ParseCSVFile(fileStream, true);
foreach (string[] journal in JournalData)
{
CallContext callContext = new CallContext();
callContext.Company = journal[CompanyIndex];
callContext.Language = "en-gb";
AxdLedgerGeneralJournal journalEntity = new AxdLedgerGeneralJournal();
AxdEntity_LedgerJournalTable journalHeader = new LedgerServices.AxdEntity_LedgerJournalTable();
journalHeader.JournalName = journal[JournalNameIndex].Trim();
journalHeader.Name = journal[DescriptionHeaderIndex].Trim();
if (journal[DetailLevelIndex] != String.Empty)
{
journalHeader.DetailSummaryPostingSpecified = true;
AxdEnum_DetailSummary? parsingDetailSummary = ImportingHelper.EnumUtils.Parse<AxdEnum_DetailSummary>("Detail");
if (parsingDetailSummary != null)
journalHeader.DetailSummaryPosting = (AxdEnum_DetailSummary) parsingDetailSummary;
}
else
journalHeader.DetailSummaryPostingSpecified = false;
journalHeader.DetailSummaryPosting = AxdEnum_DetailSummary.Detail;
AxdEntity_LedgerJournalTrans journalLine = new AxdEntity_LedgerJournalTrans();
if (journal[TransDateIndex] != null)
{
journalLine.TransDateSpecified = true;
journalLine.TransDate = DateTime.Parse(journal[TransDateIndex]);
}
else
journalLine.TransDateSpecified = false;
if (journal[AccountTypeIndex] != null)
{
journalLine.AccountTypeSpecified = true;
AxdEnum_LedgerJournalACType? parsingLedgerJournalACType = ImportingHelper.EnumUtils.Parse<AxdEnum_LedgerJournalACType>(journal[AccountTypeIndex]);
if (parsingLedgerJournalACType != null)
journalLine.AccountType = (AxdEnum_LedgerJournalACType)parsingLedgerJournalACType;
}
else
journalLine.AccountTypeSpecified = false;
AxdType_MultiTypeAccount LedgerDimension = new AxdType_MultiTypeAccount();
LedgerDimension.DisplayValue = journal[LedgerDimensionOnDisplayValueIndex];
LedgerDimension.Account = journal[LedgerDimensionMainAccountIndex];
journalLine.LedgerDimension = LedgerDimension;
journalLine.Txt = journal[DescriptionOnLineIndex];
if (journal[DebittIndex] != String.Empty)
{
journalLine.AmountCurDebitSpecified = true;
journalLine.AmountCurDebit = Decimal.Parse(journal[DebittIndex]);
}
else
journalLine.AmountCurDebitSpecified = false;
if (journal[CreditIndex] != String.Empty)
{
journalLine.AmountCurCreditSpecified = true;
journalLine.AmountCurCredit = Decimal.Parse(journal[CreditIndex]);
}
else
journalLine.AmountCurCreditSpecified = false;
if (journal[OffsetAccountTypeIndex] != String.Empty)
{
journalLine.OffsetAccountTypeSpecified = true;
AxdEnum_LedgerJournalACType? parsingLedgerJournalACType = ImportingHelper.EnumUtils.Parse<AxdEnum_LedgerJournalACType>(journal[OffsetAccountTypeIndex]);
if (parsingLedgerJournalACType != null)
journalLine.OffsetAccountType = (AxdEnum_LedgerJournalACType)parsingLedgerJournalACType;
}
else
journalLine.OffsetAccountTypeSpecified = false;
AxdType_MultiTypeAccount ledgerOffsetDimension = new AxdType_MultiTypeAccount();
ledgerOffsetDimension.Account = journal[OffsetMainAccountIndex];
ledgerOffsetDimension.DisplayValue = journal[OffsetDisplayAccountIndex];
journalLine.OffsetLedgerDimension = ledgerOffsetDimension;
journalLine.CurrencyCode = journal[CurrencyIndex];
journalLine.OffsetCompany = journal[OffsetCompanyIndex];
journalLine.Company = journal[FromCompanyIndex];
AxdEntity_LedgerJournalTrans[] journalTransCollection = new AxdEntity_LedgerJournalTrans[1]
{
journalLine
};
journalHeader.LedgerJournalTrans = journalTransCollection;
journalEntity.LedgerJournalTable =
new AxdEntity_LedgerJournalTable[1]
{
journalHeader
};
generalJournalServiceClient.create(callContext, journalEntity);
}
}
catch (Exception ex)
{
String message = ex.Message;
}
finally
{
generalJournalServiceClient.Close();
}
If somebody knows how to solve this problem, please let me know. Transactions between Banks and Ledgers are possible. But transactions between Bank and Customer are not possible. I am getting the error:
The offset account type must be one of the following types: Ledger, Bank.