Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Modify customized field on posted vendor invoice journal

(0) ShareShare
ReportReport
Posted on by 45

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);

}
}

  • CU24122009-0 Profile Picture
    45 on at
    RE: Modify customized field on posted vendor invoice journal

    Thanks Gunjan for your reply,

    I have asked for this alternate solution to the client.

  • CU24122009-0 Profile Picture
    45 on at
    RE: Modify customized field on posted vendor invoice journal

    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.

  • Martin Dráb Profile Picture
    232,866 Most Valuable Professional on at
    RE: Modify customized field on posted vendor invoice journal

    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.

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Modify customized field on posted vendor invoice journal

    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.

  • CU24122009-0 Profile Picture
    45 on at
    RE: Modify customized field on posted vendor invoice journal

    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.

  • WillWU Profile Picture
    22,352 on at
    RE: Modify customized field on posted vendor invoice journal

    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.

  • Martin Dráb Profile Picture
    232,866 Most Valuable Professional on at
    RE: Modify customized field on posted vendor invoice journal

    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?

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,110 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans