How to add custom fields in price disc view trade agreement view form

Hello Team,
I need to populate the custom field value from pricediscadmtrans to pricedisctable.
I had used pricediscadmcheckpost class to add the custom field in the field list macro.I also added the initFrompricediscadmtrans & Initfrompricedisctable from pricedisctable method. I used pack and unpack method to add the custom fields in the macro but still no luck. Custom field value is empty.

Hi Team,
I had written the below code,
Extensionof(classstr(pricediscadmcheckpost))]
Public final class tes
{
#LocalMacro.FieldList_Extended
#FieldList,
Standard fields,
Custom fields
#EndMacro
}

Please correct me if I did anything wrong here.

Isn’t PriceDictTable.initFromPriceDiscAdm() the right place?

I assigned the field in this method as well.
I had mentioned in the initial thread

Okay, so what did you find when you debugged your code? Is it called at all? Does it fail to set the value, or does the value disappear later?

Instead of writing random pieces of code, you need to analyze the problem.

Debugger not hitting in this method.

Make sure that you’re able to debug the model at all; you might have debugging disabled for the model, you may be debugging a wrong process or so. That is doesn’t stop on your breakpoint doesn’t necessarily mean that the code doesn’t get called.

If none of the methods get called in your case, writing any code there is a waste of time. You can use the debugger to walk through the code that is used during the posting to find the right place for your change.

Personally, I would start debugging with insert() method of PriceDiscAdmTrans table and then look at code leading to the insertion.

I can able to debug for the other process ,only this method is not hitting. Debugger is not even hitting till I post the agreement journal.

Hi Martin,
I have this exact situation but the below blog reference is for ax2012.
https://community.dynamics.com/forums/thread/details/?threadid=4aad74ff-2f56-4845-885d-922c1ddb4f7e
Please advise on this.

Seriously, you must find the logic that you want to change before you can start designing any code changes.

It seems that you still haven’t found it, so let me do an analysis for you and show you another way how you can do these things in future.

You already know that the process is in PriceDiscAdmCheckPost, but you don’t where. It’s a descendant of RunBase class, therefore when the process runs, run() method gets executed. There you’ll find a call of PriceDiscAdmCheckPost::runFromContract(), which calls postJournal(), which calls postJournalPost(). There you’ll find the call of createOrUpdatePriceDiscTableRecords(). The name suggests that this is what you need.

The creation of new records is done by this call:

PriceDiscTableCopyFromPriceDiscAdmTrans::newFromPurchTableVersion(journalNum).execute();

That a huge progress. Now you know which class and method contain the logic you’re interested in.

This is how execute() looks like:

public final void execute()
{
    this.init();
    Query::insert_recordset(targetCursor, fieldMappingForExecution, insertRecordSetQuery);
    this.onExecuted();
}

To modify the logic, you need to have your custom field inside fieldMappingForExecution and the query must include your field.

I think you don’t have to worry about the query. To extend the map, create a CoC extension of initFieldMapping() and use insertFieldMap() method. For example:

this.insertFieldMap(
    this.priceDiscAdmTransDatasourceId(),
    tableNum(PriceDiscAdmTrans),
    fieldNum(PriceDiscAdmTrans, MyField),
    tableNum(PriceDiscTable),
    fieldNum(PriceDiscTable, MyField));

Thank you so much Martin,above code working as expected.