Skip to main content
Solved

Custom feature problem: Create Blanket Sales order button


I have created a shortcut button for Create Blanket Sales Order on the Sales Order Menu and on the Customers three dots menu.

This feature is used to: from creating a customer to creating a blanket sales order in a single click.

However, I have a problem: when I click the "Create Blanket Sales Order" button, it goes to the Sales Orders page then I notice that the "Create Child Orders" button is not displayed.


Also it works properly if I select the order type manually.
 

Please help me see if I am wrong or missing any part of the code. Thank you everyone for your help.

Here is the code
----------------------------------------------------------------------------------------------------------
namespace PX.Objects.AR
{
 
    [PXCacheName("SOOrder Extension")]
    public class SOOrderExt : PXCacheExtension<SOOrder>
    {
        #region UsrCreateChildOrders
        [PXBool]
        [PXUIField(DisplayName = "Create Child Orders")]
        public virtual bool? UsrCreateChildOrders { get; set; }
        public abstract class usrCreateChildOrders : PX.Data.BQL.BqlBool.Field<usrCreateChildOrders> { }
        #endregion
    }
  
          
     public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint>
    {
        public PXAction<Customer> newBlanketSalesOrder;

        [PXUIField(DisplayName = "Create Blanket Sales Order")]
        [PXButton]
        public virtual IEnumerable NewBlanketSalesOrder(PXAdapter adapter)
        {
            Customer customer = Base.BAccount.Current;
            if (customer != null && customer.BAccountID > 0L)
            {
                SOOrderEntry soEntry = PXGraph.CreateInstance<SOOrderEntry>();
                soEntry.Clear();
                SOOrder newDoc = (SOOrder)soEntry.Document.Cache.Insert();
                newDoc.BranchID = null;
                soEntry.Document.Cache.SetValueExt<SOOrder.customerID>(newDoc, customer.BAccountID);
                soEntry.Document.Cache.SetValueExt<SOOrder.orderType>(newDoc, "BL"); // Set SOOrder Type here
                newDoc.ContactID = customer.PrimaryContactID < 0L ? null : customer.PrimaryContactID;
                soEntry.customer.Current.CreditRule = customer.CreditRule;
                if (soEntry.Document.Current.FreightTaxCategoryID != null)
                {
                    SOOrder createdOrder = (SOOrder)soEntry.Document.Cache.CreateCopy(soEntry.Document.Current);
                    soEntry.Document.Current.FreightTaxCategoryID = null;
                    soEntry.Document.Update(createdOrder);
                }

                // Update the order type configuration check
                var orderType = PXSelect<SOOrderType,
                    Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.
                    Select(Base, "BL").FirstOrDefault();

                if (orderType != null && orderType.GetItem<SOOrderType>().Behavior != "BL")
                {
                    throw new PXException("The specified Order Type is not configured as a Blanket Order Type.");
                }

                throw new PXRedirectRequiredException(soEntry, "SO301000");
            }
            return adapter.Get();
        }
    }        
 }
​​​​​​​

Best answer by Zoltan Febert

Hi @VinhPhat68,

I refactored your code a bit and tested it in 22R207, it worked as expected.

        [PXUIField(DisplayName = "Create Blanket Sales Order")]
        [PXButton]
        public virtual IEnumerable NewBlanketSalesOrder(PXAdapter adapter)
        {
            // Update the order type configuration check
            var orderType = (SOOrderType)PXSelect<SOOrderType,
                    Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.
                Select(Base, "BL").FirstOrDefault();

            if (orderType != null && orderType.Behavior != "BL")
            {
                throw new PXException("The specified Order Type is not configured as a Blanket Order Type.");
            }

            var customer = Base.BAccount.Current;
            if (customer != null && customer.BAccountID > 0L)
            {
                var soEntry = PXGraph.CreateInstance<SOOrderEntry>();

                var newDoc = soEntry.Document.Insert(new SOOrder
                {
                    BranchID = null,
                    CustomerID = customer.BAccountID,
                    OrderType = "BL",
                    ContactID = customer.PrimaryContactID < 0L ? null : customer.PrimaryContactID,
                    FreightTaxCategoryID = null
                });

                throw new PXRedirectRequiredException(soEntry, "SO301000");
            }
            return adapter.Get();
        }

 

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

2 replies

Zoltan Febert
Jr Varsity I
Forum|alt.badge.img+3
  • Jr Varsity I
  • 176 replies
  • Answer
  • July 19, 2023

Hi @VinhPhat68,

I refactored your code a bit and tested it in 22R207, it worked as expected.

        [PXUIField(DisplayName = "Create Blanket Sales Order")]
        [PXButton]
        public virtual IEnumerable NewBlanketSalesOrder(PXAdapter adapter)
        {
            // Update the order type configuration check
            var orderType = (SOOrderType)PXSelect<SOOrderType,
                    Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.
                Select(Base, "BL").FirstOrDefault();

            if (orderType != null && orderType.Behavior != "BL")
            {
                throw new PXException("The specified Order Type is not configured as a Blanket Order Type.");
            }

            var customer = Base.BAccount.Current;
            if (customer != null && customer.BAccountID > 0L)
            {
                var soEntry = PXGraph.CreateInstance<SOOrderEntry>();

                var newDoc = soEntry.Document.Insert(new SOOrder
                {
                    BranchID = null,
                    CustomerID = customer.BAccountID,
                    OrderType = "BL",
                    ContactID = customer.PrimaryContactID < 0L ? null : customer.PrimaryContactID,
                    FreightTaxCategoryID = null
                });

                throw new PXRedirectRequiredException(soEntry, "SO301000");
            }
            return adapter.Get();
        }

 


  • Author
  • Freshman I
  • 1 reply
  • July 20, 2023
zfebert56 wrote:

Hi @VinhPhat68,

I refactored your code a bit and tested it in 22R207, it worked as expected.

        [PXUIField(DisplayName = "Create Blanket Sales Order")]
        [PXButton]
        public virtual IEnumerable NewBlanketSalesOrder(PXAdapter adapter)
        {
            // Update the order type configuration check
            var orderType = (SOOrderType)PXSelect<SOOrderType,
                    Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.
                Select(Base, "BL").FirstOrDefault();

            if (orderType != null && orderType.Behavior != "BL")
            {
                throw new PXException("The specified Order Type is not configured as a Blanket Order Type.");
            }

            var customer = Base.BAccount.Current;
            if (customer != null && customer.BAccountID > 0L)
            {
                var soEntry = PXGraph.CreateInstance<SOOrderEntry>();

                var newDoc = soEntry.Document.Insert(new SOOrder
                {
                    BranchID = null,
                    CustomerID = customer.BAccountID,
                    OrderType = "BL",
                    ContactID = customer.PrimaryContactID < 0L ? null : customer.PrimaryContactID,
                    FreightTaxCategoryID = null
                });

                throw new PXRedirectRequiredException(soEntry, "SO301000");
            }
            return adapter.Get();
        }

.

 

Hi @zfebert56
Thank you for your help. The above code seems to have worked.


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