Hello everyone!
I need some help in understanding how to change the default value of a field in a standard form through extension. I have searched both in this forum and on google, finding some different solutions, but I noone of them have worked for me (or, maybe, I have applied them in the wrong way). I am working on dynamics 365 version 10.0.29
Here is my case in detail:
- When you have to post a new vendor invoice, you go to Accunts payable -> Invoices -> Invoice Journal. Here, you create a new journal, then you open it clicking on its voucher or on the "Lines" button above. In this form there is a tab called "Invoice" and inside it a group called "Approve". In this group there is a flag called "Approved" that's true by default, and a lookup called "Approved by" with the name of the approver. All these things are standard Microsoft.
- What I need to achive is to change the default values of the field so that the flag is false by default and the user will eventually change it if needed, and the lookup should be empty.
- This fields should be on the "LedgerJournalTrans" table, as far as I know.
- As I am extending the standard, I have a limted range of choices to achive it: I can't change the default value of the fields from the form extension in Visual Studio, and I can't use the methods but only the events provided.
- I tried retrieving the controls of the form and changing their values; I tried retrieving the datasource in various points of execution (form init, datasource init, etc) and change the values of the fields directly on it... Sometimes I received a null pointer exception, sometimes I had no errors but the fields were unchanged.
- Searching in the code, I suspect that there is some standard code that initialize this fields automatically based on the type of journal you are using, but I am not sure. In particular, I suspect that the ckass LedgerJournalEngine is involved in a way I still don't understand, but maybe I am wrong.
I thught that would be an easy task, but seems I was wrong. I hope anyone will be able to help me.
Please verify the answers which ever helped you.
Hi everyone!
I have done what I say here, using COC on the method initValue of the class LedgerJournalEngine_VendInvoice: first it calls next on it, then I change the values to what I need. It works!
Thanks everyone for the help!
Hi Andrea, Approver and Approved field is mapped in couple of forms & classes as below. How about extending insert method of LedgerJournalTrans table and check if LedgerJournalType is VendInvoiceRegister (For LedgerJournalTable9 menu item) then empty these two fields before calling next statement.
Hi Martin,
you are right. In fact, it was one of the things I did, but I have not mentioned everything in my first post or it would have been to much long ;-)
Anyway, the flag control refers to table "LedgerJournalTrans" and to its field "approved" as you can see:
Trying to follow the flag field, at this point the problem I had was that it has 191 references, quite a lot:
It was here that I found of the LedgerJournalEngine class I mentioned in the first post, in particular there is an extension class for it called LedgerJournalEngine_VendInvoice that as has a method inside called initValue that initialize my two fields:
Do you think I should try to use COC on that method and see if it works? I just thought of it now while writing, I will try and let you know...
Adding to Martin, once you found exact field name, just go to table, find ref and see wherever it is used and try checking how this default is made. That will give you exact place. Also, you can try doing a COC for init() or initValue() or post eventhandler for the same.
The first step is finding which field the control is bound to, if any. Just assuming that it's a field on LedgerJournalTrans isn't good enough. You should be able to find the information in Fom information form. Then you can use references to see where the field is used.
If you find that the control isn't bound to any field, copy the name of the control, open the form definition and search for code using the control.
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,836
Most Valuable Professional
nmaenpaa
101,156