Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How can I set 'approved by', 'approved' from OData?

(0) ShareShare
ReportReport
Posted on by 45

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

  • daehyun Profile Picture
    45 on at
    RE: How can I set 'approved by', 'approved' from OData?

    Hi Jii, Thank you for your response. I will try it on. :)

    Thanks,

  • daehyun Profile Picture
    45 on at
    RE: How can I set 'approved by', 'approved' from OData?

    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,

  • daehyun Profile Picture
    45 on at
    RE: How can I set 'approved by', 'approved' from OData?

    Hi Zvika. Thank you for your advice. But I did not use "DAT". It is just sample. :)

  • Suggested answer
    JII SAADUDDIN Profile Picture
    1,832 on at
    RE: How can I set 'approved by', 'approved' from OData?

    Hi daehyun, just right click the table or the place where do you want to display the files > Personalize > add fields

  • Suggested answer
    ZvikaR Profile Picture
    142 on at
    RE: How can I set 'approved by', 'approved' from OData?

    Are you creating transactions in the "DAT" company? (as your script indicates)

    That's a really really bad idea.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 48

#3
Zain Mehmood Profile Picture

Zain Mehmood 6 Moderator

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans