Skip to main content
Solved

Need Help with a CreateSrvOrdDocument Delegate


Forum|alt.badge.img

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?

 

Best answer by mjgrice32

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;
        }
    }
}

 

View original
Did this topic help you find an answer to your question?

3 replies

Sagar Greytrix
Captain II
Forum|alt.badge.img+3

Hi @mjgrice32 ,

I got similar forum to answer your question.

Could you please go through This forum?

Hope, this will help!

Regards,

Sagar 


Forum|alt.badge.img
  • Author
  • Varsity I
  • 76 replies
  • December 14, 2023

@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.

 


Forum|alt.badge.img
  • Author
  • Varsity I
  • 76 replies
  • Answer
  • December 14, 2023

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;
        }
    }
}

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings