Hi,
I try to create Ledger Journal from OData and I can successfully create record.
but I need to set 'approved by', 'approved' field.
Here is my source code:
---------------------------------------------------------
//Import to AX
DataServiceCollection<LedgerJournalHeader> generalJournalCollection = new DataServiceCollection<LedgerJournalHeader>(context);
//create General Journal header
LedgerJournalHeader generalJournal = new LedgerJournalHeader();
generalJournalCollection.Add(generalJournal);
generalJournal.JournalName = "testJournal";
generalJournal.Description = "testdescription";
generalJournal.DataAreaId = "DAT";
DataServiceResponse res1 = null;
res1 = context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset);
string strJournalbatch = "";
foreach (ChangeOperationResponse change in res1)
{
// Get the descriptor for the entity.
EntityDescriptor descriptor = change.Descriptor as EntityDescriptor;
if (descriptor != null)
{
LedgerJournalHeader LedgerJournalres = descriptor.Entity as LedgerJournalHeader;
if (LedgerJournalres != null)
{
strJournalbatch = LedgerJournalres.JournalBatchNumber;
Console.WriteLine("New JournalBatchNumber {0}.", strJournalbatch);
}
}
}
//create General Journal line
DataServiceCollection<LedgerJournalLine> generalJournalLineCollection = new DataServiceCollection<LedgerJournalLine>(context);
LedgerJournalLine generalJournalLine = new LedgerJournalLine();
LedgerJournalLine generalJournalLine2 = new LedgerJournalLine();
generalJournalLineCollection.Add(generalJournalLine);
generalJournalLineCollection.Add(generalJournalLine2);
generalJournalLine.AccountType = LedgerJournalACType.Cust;
generalJournalLine.AccountDisplayValue = "testCustomer";
generalJournalLine.Text = "test";
generalJournalLine.JournalBatchNumber = strJournalbatch;
generalJournalLine.Company = "DAT";
generalJournalLine.DebitAmount = 1000;
generalJournalLine.OffsetAccountType = LedgerJournalACType.Ledger;
generalJournalLine.OffsetAccountDisplayValue = "----";
generalJournalLine.OffsetCompany = "DAT";
generalJournalLine.Invoice = "INV-001";
generalJournalLine.CurrencyCode = "USD";
generalJournalLine.DataAreaId = "DAT";
generalJournalLine.PostingProfile = "12345";
Console.WriteLine(string.Format("LedgerJournalACType.Vend {0} - !", (int)(LedgerJournalACType.Vend)));
generalJournalLine2.AccountType = LedgerJournalACType.Vend;
generalJournalLine2.AccountDisplayValue = "2001";
generalJournalLine2.JournalBatchNumber = strJournalbatch;
generalJournalLine2.Company = "DAT";
generalJournalLine2.CreditAmount = 1000;
generalJournalLine2.OffsetAccountType = LedgerJournalACType.Ledger;
generalJournalLine2.OffsetAccountDisplayValue = "----";
generalJournalLine2.OffsetCompany = "DAT";
generalJournalLine2.Invoice = "INV-001";
generalJournalLine2.CurrencyCode = "USD";
generalJournalLine2.DataAreaId = "DAT";
context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset); // Batch with Single Changeset ensure the saved changed runs in all-or-nothing mode.
Console.WriteLine(string.Format("Invoice {0} - Saved !", strJournalbatch));
---------------------------------------------------------
When I create General Journal manually, 'approved by', 'approved' field was set automatically. But from OData did not setting.( And LedgerJournalLine do not have 'approved by', 'approved' )
If you have any solution, Please share to me.
Thanks,
*This post is locked for comments
Hi Jii, Thank you for your response. I will try it on. :)
Thanks,
Thanks sukrut. But I am sorry, I don't know how to add the fields.
If you share how to add the fields to OData, I am very glad it.
Thanks,
Hi Zvika. Thank you for your advice. But I did not use "DAT". It is just sample. :)
Hi daehyun, just right click the table or the place where do you want to display the files > Personalize > add fields
Are you creating transactions in the "DAT" company? (as your script indicates)
That's a really really bad idea.
Mohamed Amine Mahmoudi
100
Super User 2025 Season 1
Community Member
48
Zain Mehmood
6
Moderator