Announcements
Hi guys,
I am using D365FO.
I want to make a customized field editable on the Posted vendor invoice journal.
For this, I am implementing LedgerJournalTable form's datasource Activated event handler.
And I am able to achieve the requirement up to make only one field(customized field) editable and all other non-editable for posted invoice journal records.
But getting below error on modifying,
"Journal has already been posted and, consequently, is not open."
Code for Event handler as below,
[FormDataSourceEventHandler(formDataSourceStr(LedgerJournalTable, LedgerJournalTable), FormDataSourceEventType::Activated)]
public static void LedgerJournalTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
{
LedgerJournalTable ledgerJournalTable;
DictTable dictTable = new DictTable(ledgerJournalTable.TableId);
int i;
int fieldNumber;
LedgerJournalTable currentLedgerJournalTable = sender.cursor();
FormRun formRun = sender.formRun();
FormDataSource LedgerJournalTable_ds = formRun.dataSource(formDataSourceStr(LedgerJournalTable,LedgerJournalTable));
if(currentLedgerJournalTable.Posted)
{
LedgerJournalTable_ds.allowEdit(true);
for(i = 1;i <= dictTable.fieldCnt();i++)
{
fieldNumber = dictTable.fieldCnt2Id(i);
if(LedgerJournalTable_ds.object(fieldNumber))// && fieldNumber != fieldNum(LedgerJournalTable,COC_Remark1))
{
LedgerJournalTable_ds.object(fieldNumber).allowEdit(false);
}
}
LedgerJournalTable_ds.object(fieldNum(LedgerJournalTable,COC_Remark1)).allowEdit(true);
}
}
Thanks Gunjan for your reply,
I have asked for this alternate solution to the client.
Thanks, Martin,
We will look to redesign the solution for this requirement.
Ad will try to put the Remark field in any linked table to LedgerJournalTable.
Thank you very much for your reply.
Have you considered putting the field to a separate table linked to LedgerJournalTable? With this approach, you don't have to change (or bypass) validation logic of LedgerJournalTable, because you won't update LedgerJournalTable at all.
You can try creating a form with pattern dialog. You can refer to LedgerJournalTransDimension as an example. This form will have only the Remarks control.
On opening the form, you can default this control with the current "Remaks" value on LedgerJournalTrans and on closing the form you can update the field in LedgerJournalTrans table using 'doUpdate' statement to bypass the validation.
Thanks, Martin for your reply and simplifying my code.
I have added on one customized Remark field in LedgerJournalTable table and LedgerJournlTable form.
The client asked for allowing to modify the Remark field for posted/Unposted vendor invoice journal.
But due to validation on the table, I am unable to modify the field value.
How can I bypass the validation in the case of Remark field validation?
Thanks in advance.
Hi akkatisuresh,
You can't edit posted journal, it is only possible to change it in SQL directly or write a job with x++ statements and use the doUpdate() command to bypass the update validation checks.
As Martin said, please tell us your need and rethink the design.
Please don't ask questions about D365FO in the Dynamics AX forum. I moved this thread to Dynamics 365 Finance forum.
Also, please always use Insert > Insert Code (in the rich-formatting view) to paste source code. It'll become easier to read. I also simplified your code a bit:
FormDataSourceEventHandler(formDataSourceStr(LedgerJournalTable, LedgerJournalTable), FormDataSourceEventType::Activated)] public static void LedgerJournalTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e) { DictTable dictTable = new DictTable(tableNum(LedgerJournalTable)); LedgerJournalTable currentLedgerJournalTable = sender.cursor(); FormRun formRun = sender.formRun(); FormDataSource ledgerJournalTable_ds = formRun.dataSource(formDataSourceStr(LedgerJournalTable, LedgerJournalTable)); if (currentLedgerJournalTable.Posted) { ledgerJournalTable_ds.allowEdit(true); for (int i = 1; i <= dictTable.fieldCnt(); i ) { int fieldNumber = dictTable.fieldCnt2Id(i); if (ledgerJournalTable_ds.object(fieldNumber)) { ledgerJournalTable_ds.object(fieldNumber).allowEdit(false); } } ledgerJournalTable_ds.object(fieldNum(LedgerJournalTable, COC_Remark1)).allowEdit(true); } }
Nevertheless just making the field editable doesn't bypass validations.
What is the field about? Have you considered putting it to a separate table linked to LedgerJournalTable?
André Arnaud de Cal...
294,110
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator