Solved

Error When Creating Opportunity through Customization

  • 23 August 2022
  • 2 replies
  • 74 views

Userlevel 4
Badge +1

Hello,

I am currently trying to add a button to Cases where I can create an opportunity. See below for graph initiation and insert. Note that this is proof of concept.

    #region Actions

public PXAction<PX.Objects.CR.CRCase> CreateOpportunity;

[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Create Opportunity")]
protected void createOpportunity()
{
CRCase cCase = Base.Case.Current;

OpportunityMaint graph = PXGraph.CreateInstance<OpportunityMaint>();

CROpportunity opty = new CROpportunity
{
BAccountID = cCase.CustomerID,
ContactID = cCase.ContactID,
//Status = "N",
//ClassID = "SERVICE",
//StageID = "L",
Subject = cCase.Subject
};

graph.Opportunity.Insert(opty);

if (graph != null)
{
PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow);
}
}

#endregion

However, I’m getting an odd error when I try to execute. See below for snip.

Any help regarding this error would be greatly appreciated.

icon

Best answer by Naveen Boga 23 August 2022, 10:35

View original

2 replies

Userlevel 7
Badge +18

Hi @rhooper91  Please use the below code, I have verified it from my end and it is working as expected.

 

 public class CRCaseMaintExt : PXGraphExtension<CRCaseMaint>
{
public PXAction<PX.Objects.CR.CRCase> CreateOpportunity;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Create Opportunity")]
protected IEnumerable createOpportunity(PXAdapter adapter)
{

CRCase cCase = Base.Case.Current;
PXLongOperation.StartOperation(Base, delegate ()
{
OpportunityMaint graph = PXGraph.CreateInstance<OpportunityMaint>();
if (cCase != null)
{

CROpportunity objcROpportunity = new CROpportunity
{
Status = "L",
StageID = "P"
};

objcROpportunity.Subject = "Test Subject";
// objcROpportunity.BAccountID = cCase.CustomerID;
graph.Opportunity.Cache.Insert(objcROpportunity);
CRContact objCrContact = graph.Opportunity_Contact.Select();
objCrContact.Email = "Test@Test.com";
objCrContact.FirstName = "Naveen";
graph.Opportunity_Contact.Cache.Update(objCrContact);
graph.Actions.PressSave();

objcROpportunity.BAccountID = cCase.CustomerID;
graph.Opportunity.Cache.Update(objcROpportunity);
graph.Actions.PressSave();
PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.Same);


}
});
return adapter.Get();
}
}

 

 

Userlevel 4
Badge +1

@Naveen Boga - that did it. I modified it a little bit, but I no longer get the error.

You are the best, I appreciate the time you spend into this and all my other questions!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved