Skip to main content
Solved

Trigger CloseAsWon action when Stage is set to Won

  • 29 May 2024
  • 7 replies
  • 56 views

Hi,

In the Opportunities screen, a client is wanting to have the CloseAsWon action triggered automatically when the Stage field is set to Won. The code below is how I have tried to set it up, but all it does is trigger a Save and nothing else happens.

Is this kind of functionality possible? If so, how would you recommend setting this up?

Let me know if I can provide any other information.

Kind regards,

Andrew

protected void CROpportunity_StageID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (CROpportunity)e.Row;
if (row == null) return;

// Check if the new value of StageID is "Won"
if (row.StageID == "W")
{

//Trigger the "Close As Won" action
TriggerCloseAsWonAction();
}
}

private void TriggerCloseAsWonAction()
{
var closeAsWonAction = Base.Actionss"CloseAsWon"];
if (closeAsWonAction != null)
{
closeAsWonAction.Press();
}
}

 

7 replies

Userlevel 4
Badge

@AndrewA , anything on the workflow which is overriding your customization? 

Userlevel 4
Badge

Also have you tried Base.CloseAsWon.Press();?

Userlevel 4
Badge

Thanks for your responses @vibindas . Unfortunatley the Base.CloseAsWon.Press() didn't work, it just did the same thing as before, which was save the change.

In the workflow section, is there a way to create a new workflow that is looking at when the Stage field changes? in the image below, it looks like the workflow is only set to look at the Status field at the moment.

 

Userlevel 4
Badge

@AndrewA , I could be wrong, but I believe wflow is defined based on the State. Could you try overriding the action in your customization.

Something like 

public PXAction<CRCase> CloseAsWon;

public virtual IEnumerable CloseAsWon(PXAdapter adapter)
{

  Base.CloseAsWon.Press();

}

Userlevel 4
Badge

Thanks for that suggestion @vibindas . Unfortunately, this didn't work.

 

If I click the ‘Close As Won’ button manually in the Opportunities screen, a pop-up window appears that asks for a Reason. Would my custom code need to have some logic that handles this? Or is this not required when triggering the action via code?

Userlevel 4
Badge

@AndrewA , you are seeing the popup window on CloseAsWon Action as it’s defined in the workflow. Please see the screenshots below. If you need to skip all this, I reckon you will need to override the Default workflow and have your own Custom workflow.

 

Userlevel 4
Badge

Ok great, thanks for your help @vibindas ! I will give the custom workflow a go.

Reply