Solved

Need Help with a CreateSrvOrdDocument Delegate

  • 14 December 2023
  • 3 replies
  • 74 views

Userlevel 4
Badge

I need to set extended fields when a Service Order is created via a Project.

I am trying to use the logic shown to me in this post: (Create Appointment With Extended Values)

But when I create this:

        public delegate IEnumerable CreateSrvOrdDocumentDelegate(PXAdapter adapter);
[PXOverride]
public IEnumerable CreateSrvOrdDocument(PXAdapter adapter, CreateSrvOrdDocumentDelegate baseMethod)
{
//Adds RowInserting handler when the ServiceOrderEntry Graph is created
PXGraph.InstanceCreated.AddHandler<ServiceOrderEntry>((graphServiceOrderEntry) =>
{
var CQ = Base.QuoteCurrent;
var currentQuote = CQ.Current;
PMQuoteExt QuoteExt = currentQuote.GetExtension<PMQuoteExt>();

graphServiceOrderEntry.RowInserting.AddHandler<PX.Objects.FS.FSServiceOrder>((sender, e) =>
{
var SvcOrderObject = (PX.Objects.FS.FSServiceOrder)e.Row;
PMServiceExt svcExt = SvcOrderObject.GetExtension<PMServiceExt>();
SvcOrderObject.DocDesc = "From Quote: " + currentQuote.QuoteNbr;
//insert Service Order Fields into Apt Values
svcExt.UsrAuthorizedByContact = QuoteExt.UsrAuthorizedByContact;
svcExt.UsrFieldSiteContact = QuoteExt.UsrFieldSiteContact;
svcExt.UsrDoorLocation = QuoteExt.UsrDoorLocation;
svcExt.UsrLaborType = QuoteExt.UsrLaborType;
svcExt.UsrProductType = QuoteExt.UsrProductType;
svcExt.UsrCustomerIsExempt = QuoteExt.UsrCustomerIsExempt;
svcExt.UsrTaxExempt = QuoteExt.UsrTaxExempt;
});
});
return baseMethod(adapter);
}

 

It compiles fine, but when I try to publish the customization, I get a “CreateSrvOrdDocument does not exist” error.

What am I missing?

 

icon

Best answer by mjgrice32 14 December 2023, 21:41

View original

3 replies

Userlevel 4
Badge

OK, just in case anyone is interested in this, and had a hard time following the other two threads through the rabbit holes, here is the class I eventually created. It compiles, and it publishes. I have not tested it yet. But this is the code (For 2022 R2):

 

using PX.Data;
using PX.Objects.CS;
using PX.Objects.PM;
using System.Collections.Generic;
using PMQuoteExt = YourNamespace.PMQuoteExt;
using PMServiceExt = YourNamespace.FSServiceOrderExt;


//NOTE: The NAMESPACE MUST be set to PX.Objects.FS or this will not work correctly
namespace PX.Objects.FS
{
/**********************************************************************************************
* DialogBoxSOApptCreation is implemented by graph extension of SM_ProjectEntry_DBox
* Which extends not just ProjectEntry graph but also first level of SM_ProjectEntry
* graph extension. Which means, we have 3 levels involved here and so in order to override,
* we must include all 3 levels (ie: SM_ProjectEntry_DBox, SM_ProjectEntry, ProjectEntry)
*********************************************************************************************/
public class ProjectEntry_DialogBoxExt : PXGraphExtension<SM_ProjectEntry_DBox, SM_ProjectEntry, ProjectEntry>
{
public static bool IsActive()
{
return PXAccess.FeatureInstalled<FeaturesSet.serviceManagementModule>();
}
// Customizations
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)
{
// Get Service Order Extension Fields
baseMethod(srvOrdGraph, apptGraph, header, details);
FSServiceOrder SvcOrderObject = (FSServiceOrder)srvOrdGraph.Caches<PX.Objects.FS.FSServiceOrder>().Current;
PMServiceExt svcExt = SvcOrderObject.GetExtension<PMServiceExt>();
// Get Project Extension Fields
var onp = Base.Project;
var currentQuote = Base.Quote.Current;
PMQuoteExt QuoteExt = currentQuote.GetExtension<PMQuoteExt>();
// Set the values. NOTE: Because we are already calling baseMethod
// we don't need to attach this to the PXGraph.InstanceCreated.AddHandler()
// as we did when we added the fields to the quote and appointment example
svcExt.UsrAuthorizedByContact = QuoteExt.UsrAuthorizedByContact;
svcExt.UsrFieldSiteContact = QuoteExt.UsrFieldSiteContact;
svcExt.UsrDoorLocation = QuoteExt.UsrDoorLocation;
svcExt.UsrLaborType = QuoteExt.UsrLaborType;
svcExt.UsrProductType = QuoteExt.UsrProductType;
svcExt.UsrCustomerIsExempt = QuoteExt.UsrCustomerIsExempt;
svcExt.UsrTaxExempt = QuoteExt.UsrTaxExempt;
}
}
}

 

Userlevel 4
Badge

@sagar07 Yes, I saw that thread, but it seems to go down a bunch of rabbit holes, (which are hard to follow at times) and the final solution shows how to set values for an appointment, but in my case, I want to set the variables pulled from the Project, and put in the ServiceOrder, and I don’t see how to get those values in the method: 

CreateDocument(ServiceOrderEntry srvOrdGraph, AppointmentEntry apptGraph, DBoxHeader header, List<DBoxDetails> details, createDocument baseMethod

EDIT: nvm. I think I see how to get the values now.

 

Userlevel 5
Badge +1

Hi @mjgrice32 ,

I got similar forum to answer your question.

Could you please go through This forum?

Hope, this will help!

Regards,

Sagar 

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