Skip to main content
Solved

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

  • June 25, 2024
  • 8 replies
  • 147 views

Forum|alt.badge.img

 

Best answer by darylbowman

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

 

8 replies

darylbowman
Captain II
Forum|alt.badge.img+15

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

 


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • June 25, 2024

Hi @darylbowman 

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

 


darylbowman
Captain II
Forum|alt.badge.img+15

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

 


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • June 25, 2024

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 


darylbowman
Captain II
Forum|alt.badge.img+15

Could you show what you have in your extension code?


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • June 25, 2024

of course @darylbowman , I send you the images:

 


darylbowman
Captain II
Forum|alt.badge.img+15

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>>();

 


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • June 25, 2024

Thank you @darylbowman …

I was very pleased with your help