Skip to main content
Solved

How to overwrite the CreateInvoice action of CRCreateInvoice for OpportunityMaint_Extension (Version 2023R2)

  • 25 June 2024
  • 8 replies
  • 55 views

 

8 replies

Badge +12

To extend or override an existing public or protected virtual Action or method, create a delegate and use the PXOverride attribute on the new method. If the objective is to extend rather than override, call the original method through the delegate at the appropriate time.

In this case, either:

public delegate IEnumerable CreateInvoiceDelegate(PXAdapter adapter);
[PXOverride]
public virtual IEnumerable createInvoice(PXAdapter adapter, CreateInvoiceDelegate baseMethod)
{
// Execute original method
var result = baseMethod(adapter);

// your code (executed after the original)
//

return result;
}

or 

public delegate IEnumerable CreateInvoiceDelegate(PXAdapter adapter);
[PXOverride]
public virtual IEnumerable createInvoice(PXAdapter adapter, CreateInvoiceDelegate baseMethod)
{
// your code (executed before the original)
//

// Execute original method
return baseMethod(adapter);
}

 

Userlevel 1
Badge

Hi @darylbowman 

I extended the original CRCreateInvoice class but I get the following:

 

Badge +12

I’m not good with Español, but the second error is arising from the fact that CRCreateInvoice is not a graph, but rather a generic extension of a graph. For this reason, I believe you’ll need to write a graph extension for the specific graph you’re targeting. For Opportunities (one entity that uses CRCreateInvoice), it would look like this:


namespace Test
{
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public class Test : PXGraphExtension<OpportunityMaint.CRCreateInvoiceExt, OpportunityMaint>
{
public delegate IEnumerable CreateInvoiceDelegate(PXAdapter adapter);
[PXOverride]
public virtual IEnumerable createInvoice(PXAdapter adapter, CreateInvoiceDelegate baseMethod)
{
// your code (executed before the original)
//

// Execute original method
return baseMethod(adapter);
}
}
}

 

Userlevel 1
Badge

Thank you, @darylbowman.

I am passing the structure of the original method to the extension but I get this error that I can't solve.

  

The first error:
Error CS0246 The type or namespace name 'TDiscountExt' was not found (is a using directive or assembly reference missing?) customizationSipecom 

Badge +12

Could you show what you have in your extension code?

Userlevel 1
Badge

of course @darylbowman , I send you the images:

 

Badge +12

I can’t see the very end of the code, but it looks like you are just duplicating the original code. In that case, you’re going to have issues, because in the generic class, it uses generic types (ie: TDiscountExt, TGraph, TMaster). Your extension is using non-generic types.

In order to make this work for this particular instance, you’d have to replace the generic types with non-generic types:

var extension = graph.GetProcessingExtension<CRCreateInvoice<OpportunityMaint.Discount, OpportunityMaint, CROpportunity>>();

 

Userlevel 1
Badge

Thank you @darylbowman …

I was very pleased with your help

Reply