Solved

How to call / override CreateSrvOrdDocument; from OpportunityMaint

  • 30 August 2023
  • 6 replies
  • 73 views

Userlevel 4
Badge

I have a variation on another post that was asked 11 moinths ago (here

In my case, my user creates lines in the Sales Quote detail that have no inventory ID. They are used as instructions for the customer. 

By default, when I am sendign this to a Service Order, it warns me that there are items with no inventory ID with a popup:

 

The opportunity contains one or multiple product lines with no inventory item specified. Click OK if you want to ignore these product lines and proceed with creating a service order. Click Cancel if you want to review the product lines and specify inventory items where necessary.

 

The problem is that I don’t to do either of these options. I want to Not have the warning, and just let it create a service order with Blank Inventory IDs.

Reading through stephenward03 thread, I have created this class, but the box comes up before I get to the creatDocument() function, so it isn’t heling me. I tried looking at the source code, but I don’t see a method that I can override to get me what I want:

 Any ideas?

using PX.Data;
using PX.Objects.CS;
using PX.Objects.FS;
using PX.Objects.PM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PX.Objects.FS
{
public class DialogBoxSOApptCreation_Ext : PXGraphExtension<SM_ProjectEntry_DBox, SM_ProjectEntry, ProjectEntry>
{
public static bool IsActive() => PXAccess.FeatureInstalled<FeaturesSet.serviceManagementModule>();

public delegate void createDocument(ServiceOrderEntry srvOrdGraph, AppointmentEntry apptGraph,
DBoxHeader header, List<DBoxDetails> details);
[PXOverride]
public void CreateDocument(ServiceOrderEntry srvOrdGraph, AppointmentEntry apptGraph,
DBoxHeader header, List<DBoxDetails> details, createDocument baseMethod)
{
baseMethod(srvOrdGraph, apptGraph, header, details);
FSServiceOrder myServiceOrder = (FSServiceOrder)srvOrdGraph.Caches<FSServiceOrder>().Current;
}
}
}

 

icon

Best answer by darylbowman 1 September 2023, 22:15

View original

6 replies

Userlevel 4
Badge

(I can’t seem to edit my original post?)

I found some errors in my previous class extension for the dialog box. But my issue is still that

  1. I can’t intercept the “check for blank InventoryIDs” and so the dialog box is still popping up
  2. The blank Inventory Items are being dropped before i get to the CREATE DOCUMENT part.

Here is the modified class:

 

using PX.Data;
using PX.Objects.CS;
using PX.Objects.PM;
using System.Collections.Generic;


using PX.Data.WorkflowAPI;
using PX.Objects.CM.Extensions;
using PX.Objects.CR;
using PX.Objects.Extensions.MultiCurrency;
using PX.Objects.IN;
using PX.SM;
using System;
using System.Collections;
using System.Linq;
using PX.Objects.CR.Workflows;


namespace PX.Objects.FS
{
public class DialogBoxSOCreation_Ext : PXGraphExtension<SM_OpportunityMaint_DBox, SM_OpportunityMaint, OpportunityMaint>
{
public CRValidationFilter<DBoxDocSettings> DocumentSettings;
public static bool IsActive() => PXAccess.FeatureInstalled<FeaturesSet.serviceManagementModule>();


public override void Configure(PXScreenConfiguration configuration)
{
var context = configuration.GetScreenConfigurationContext<ProjectEntry, PMProject>();

var servicesCategory = context.Categories.CreateNew(ToolbarCategory.ActionCategoryNames.Services,
category => category.DisplayName(ToolbarCategory.ActionCategory.Services));

context.UpdateScreenConfigurationFor(config => config
.WithActions(a =>
{
a.Add<SM_ProjectEntry_DBox>(e => e.CreateSrvOrdDocument, c => c.InFolder(servicesCategory));
a.Add<SM_ProjectEntry_DBox>(e => e.CreateApptDocument, c => c.InFolder(servicesCategory));
})
.UpdateDefaultFlow(flow =>
{
return flow.WithFlowStates(states =>
{
states.Update(ProjectStatus.Active,
state => state.WithActions(actions =>
{
actions.Add<SM_ProjectEntry_DBox>(e => e.CreateSrvOrdDocument);
actions.Add<SM_ProjectEntry_DBox>(e => e.CreateApptDocument);
}));
});
})
.WithCategories(categories =>
{
categories.Add(servicesCategory);
categories.Update(ToolbarCategory.ActionCategoryNames.Services, category => category.PlaceAfter(context.Categories.Get(ToolbarCategory.ActionCategoryNames.Commitments)));
})
);
}

public delegate void prepareDBoxDefaults();
[PXOverride]
public void PrepareDBoxDefaults()
{

var OppRow = Base.Opportunity.Current;
DocumentSettings.Current.CustomerID = OppRow.ContactID;
DocumentSettings.Current.Description = OppRow.Subject;
DocumentSettings.Cache.SetValueExt<DBoxDocSettings.branchID>(DocumentSettings.Current, OppRow.BranchID);
DocumentSettings.Cache.SetValueExt<DBoxDocSettings.projectID>(DocumentSettings.Current, OppRow.ProjectID);
}



public delegate void createDocument(ServiceOrderEntry srvOrdGraph, AppointmentEntry apptGraph,
DBoxHeader header, List<DBoxDetails> details);
[PXOverride]
public void CreateDocument(ServiceOrderEntry srvOrdGraph, AppointmentEntry apptGraph,
DBoxHeader header, List<DBoxDetails> details, createDocument baseMethod)
{
baseMethod(srvOrdGraph, apptGraph, header, details);
FSServiceOrder myServiceOrder = (FSServiceOrder)srvOrdGraph.Caches<FSServiceOrder>().Current;
}
}
}

 

Badge +11

I believe the correct way to override this method would be:

public delegate void PrepareDBoxDefaultsDelegate();
[PXOverride]
public void PrepareDBoxDefaults(PrepareDBoxDefaultsDelegate baseMethod)
{
var OppRow = Base.Opportunity.Current;
DocumentSettings.Current.CustomerID = OppRow.ContactID;
DocumentSettings.Current.Description = OppRow.Subject;
DocumentSettings.Cache.SetValueExt<DBoxDocSettings.branchID>(DocumentSettings.Current, OppRow.BranchID);
DocumentSettings.Cache.SetValueExt<DBoxDocSettings.projectID>(DocumentSettings.Current, OppRow.ProjectID);
}

 

 

Userlevel 2
Badge +1

I’m trying to override the PrepareHeaderAndDetails method on this same class and i’m getting the error: “The signature of a method with the PXOverride attribute must match the overridden method.”

If I remove the delegate the code compiles, but when I click the “Create and Review” button nothing happens.

What I’m attempting to accomplish is to exclude details lines with a specific inventory id from being added to the generated Service Order.  Any ideas?

\@darylbowman 

Userlevel 2
Badge +1

I actually have this working now, but it appears that is is executing base method and my override method.  In the screenshot you can see it added the one line twice.  The second items is the inventory id I’m trying to filter out.  It looks like it’s executing the base method first.  I’m not sure how to get around this.

   public class AHS_DialogBoxSOApptCreation : PXGraphExtension<SM_OpportunityMaint_DBox, SM_OpportunityMaint, OpportunityMaint>
{
public static bool IsActive() => PXAccess.FeatureInstalled<FeaturesSet.serviceManagementModule>();

//public delegate void PrepareHeaderAndDetailsDelegate();
//[PXOverride]
public void PrepareHeaderAndDetails(DBoxHeader header, List<DBoxDetails> details)
{
PXTrace.WriteInformation("Hit my custom PrepareHeaderAndDetails method");
if (header == null || Base2.DocumentSettings.Current == null)
{
return;
}

PX.Objects.CR.CROpportunity current = base.Base.Opportunity.Current;
FSxCROpportunity extension = base.Base.Opportunity.Cache.GetExtension<FSxCROpportunity>(current);
CRContact current2 = base.Base.Opportunity_Contact.Current;
CRShippingAddress current3 = base.Base.Shipping_Address.Current;
CRSetup current4 = base.Base1.CRSetupRecord.Current;
extension.SDEnabled = true;
extension.BranchLocationID = header.BranchLocationID;
extension.SrvOrdType = header.SrvOrdType;
header.LocationID = current.LocationID;

 

Badge +11

This would be the correct delegate declaration:

public delegate void PrepareHeaderAndDetailsDelegate(DBoxHeader header, List<DBoxDetails> details);
[PXOverride]
public void PrepareHeaderAndDetails(DBoxHeader header, List<DBoxDetails> details, PrepareHeaderAndDetailsDelegate baseMethod)
{

}

 

Userlevel 2
Badge +1

Ah! What a rookie mistake.  I copied and pasted from a different delegate and did not even notice I was missing the params in the delegate definition.  

Thank you!

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