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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Chain of command issue within same table extension

(0) ShareShare
ReportReport
Posted on by 657

Hi,

The setup is simple, one extension class for the table SMAServiceOrderTable and within that 3 methods.

initFromAgreement is an existing method which I wanted to extend via chain of command/

initFromServiceObjectId is a new method which is called from the SMAServiceOrder form when the PWBServiceObjectId field has changed.

The last method is of no importance in this example.

So I call the initFromServiceObjectId method from my form, he finds the agreement (only one active) and then I call this.initFromAgreement(false) from within that new method.

He jumps to the initFromAgreement method in my class but immediatly throws an error : Object reference not set to an instance of an object

I went into debug and found that 'this' (which is the table) is null once it gets into my extension method.

So the object on which the method is called, suddenly is disposed ....

I'm on U12 of D365 Ops, U13 is not yet available in Europe.

Can this be considered a bug or am I missing something?

Here is my code.

[ExtensionOf(tablestr(SMAServiceOrderTable))]
final class PWBSMAServiceOrderTable_Extension
{
public void initFromAgreement(boolean checkUpdateDate = false)
{
next initFromAgreement(checkUpdateDate);

SMAAgreementTable agreementTable = SMAAgreementTable::find(this.AgreementId);
this.PWBServiceObjectId = agreementTable.PWBServiceObjectId;
this.initFromServiceObjectId(true);


}

public void initFromServiceObjectId(boolean setByAgreement = false)
{
if (this.PWBServiceObjectId)
{
SMAServiceObjectTable serviceObject = SMAServiceObjectTable::find(this.PWBServiceObjectId);
this.PWBRouteId = serviceObject.PWBRouteId;

if (!setByAgreement)
{
//TODO Get Agreement and set it here
SMAAgreementTable agreementTable;

select firstonly * from agreementTable
where agreementTable.StartDate <= systemDateGet() &&
agreementTable.EndDate >= systemDateGet() &&
agreementTable.PWBServiceObjectId == this.PWBServiceObjectId;

if (agreementTable)
{
this.AgreementId = agreementTable.AgreementId;
this.initFromAgreement(false);
}

}
}
}

public void initValue()
{
next initValue();

this.PWBSMAServiceTaskId = SMAParameters::find().PWBCallBackSMAServiceTaskId;
}

}

*This post is locked for comments

I have the same question (0)
  • Mea_ Profile Picture
    60,286 on at

    Hi Sven Peeters Prodware ,

    You code looks ok apart of the fact that you are calling initFromAgreement in initFromServiceObjectId that is called from initFromAgreement, looks like infinitive loop here. If it's not cause by the loop, please try to rebuild a model.

  • Sven Peeters Prodware Profile Picture
    657 on at

    Hi,

    It isn't an infinite loop because when I call initFromServiceObjectId from initFromAgreement, I always set setByAgreement = true. This avoids the infinite loop.

    Already tried a full compile but to no avail :-(

    Now that I'm sure it must be an internal issue (not in my code), I'm gonna duplicate some code to prevent the issue. I'm on a tight deadline, so can't wait a few weeks (maybe months) to get a solution from MS.

    Thank you for the quick code review

  • Mea_ Profile Picture
    60,286 on at

    So if you debut it, it goes to initFromServiceObjectId and fails on if (this.PWBServiceObjectId) line or somewhere else?

  • Sven Peeters Prodware Profile Picture
    657 on at

    Hi,

    It has something to do with the CoC method. If this method is called from standard code, 'this' is also null. So something to do with the CoC on that initFromAgreement method.

  • Sven Peeters Prodware Profile Picture
    657 on at

    So I abandonned the Coc approach and used a post event on the method.

    Does more or less the same thing in this case.

    I do get the impression that Coc is much more complex (internally) then a simple event delegate.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Basit Profile Picture

Basit 1

#1
GL-01081504-0 Profile Picture

GL-01081504-0 1

#1
Roya Profile Picture

Roya 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans