0

I have this customization where I want the user to click on the new action menu in the Opportunities screen named Create Project where it redirects or pops up the project entry screen and once it is saved redirects back to opportunity screen with the created project selected in the project field.

Here's my code so far, which I tried to copy from other similar module, but problem is that it's not updating the project field in the Oppurtunity screen after Save&Close on Create Project popup.

public class OpportunityMaint_Extension:PXGraphExtension<OpportunityMaint> {

    public override void Initialize() { 
        Base.Action.AddMenuAction(createProject);
        createSalesOrder.SetVisible(false);
        createSalesOrder.SetEnabled(false);  
    }

    public PXAction<PX.Objects.CR.CROpportunity> createSalesOrder;

    [PXUIField(Visible = false)]
    public IEnumerable CreateSalesOrder(PXAdapter adapter) {
        return null;
    }


    public PXAction<PX.Objects.CR.CROpportunity> createProject;

    [PXUIField(DisplayName = "Create Project", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Select)]
    [PXButton()]
    public IEnumerable CreateProject(PXAdapter adapter) {
        List<CROpportunity> opportunities = new List<CROpportunity>(adapter.Get().Cast<CROpportunity>());

        foreach (CROpportunity opp in opportunities) {
            Base.Save.Press(); 
            PXLongOperation.StartOperation(Base, () => ConvertToProject(opp)); 
        }

        return opportunities;
    }

    public static void ConvertToProject(CROpportunity opportunity) {
        ProjectEntry projectEntry = PXGraph.CreateInstance<ProjectEntry>();
        PMProject proj = new PMProject {
            ContractCD = (string)"<NEW>",
            CustomerID = opportunity.BAccountID,
            Description = opportunity.OpportunityName,
            OwnerID = opportunity.OwnerID
        };

        proj = projectEntry.Project.Insert(proj);
        opportunity.ProjectID = proj.ContractID; 

        throw new PXRedirectRequiredException(projectEntry , "Create Project", true); 
    }

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

        //createProject.SetEnabled(true);
        createSalesOrder.SetVisible(false);
        createSalesOrder.SetEnabled(false);
    }
}
Monasha
  • 711
  • 2
  • 16
  • 27
Jo Div
  • 13
  • 2

2 Answers2

0

Try to add popup command cancel to the .aspx file of the page. Put something like that <px:PXDSCallbackCommand Name="YourAction" Visible="True" CommitChanges="True" PopupCommand="Cancel" PopupCommandTarget="ds" /> to your action declaration in the aspx.

Dmitrii Naumov
  • 1,692
  • 8
  • 17
0

We ran into something similar. The problem is once you open the page as a new tab/page in the browser there is no true link back to the previous page. What we did was make the call to the other graph a pop up in the calling graph by using one of the following:

  • PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.Popup)
  • throw new PXPopupRedirectException(graph, string.Empty, true)

The only down side to this is the default pop up panel size is small and not adjustable in the page or code file dynamically. You can increase the size with a fixed value as I found out here:

Changing the height/width when calling another graph as an in-page popup using PXPopupRedirectException

If you can pass the opportunity to your project graph before calling it, you could then use that to update the opportunity when saving the new project. And when the panel closes it should refresh your opportunity with the new value.

Community
  • 1
  • 1
Brendan
  • 5,428
  • 2
  • 17
  • 33