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