web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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

I have the same question (0)
  • Suggested answer
    ZvikaR Profile Picture
    168 on at

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

    That's a really really bad idea.

  • Suggested answer
    JII SAADUDDIN Profile Picture
    1,832 on at

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

  • daehyun Profile Picture
    45 on at

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

  • daehyun Profile Picture
    45 on at

    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

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

    Thanks,

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans