1

How to bring in Business Accounts which are classified as both Customer and Vendor via Import Scenario in Acumatica?

DChhapgar
  • 2,280
  • 12
  • 18

2 Answers2

4

Out-of-box Extend To Vendor action cannot be used in Import Scenario since it redirects to vendor screen with pre-populated data and user has to manually save the vendor.

In below code snippet, we are creating a new hidden action which invokes base Extend Customer To Vendor action and persists the vendor data rather redirecting to vendor screen.

using System;
using System.Collections;
using PX.Data;
using PX.Objects.AR;

namespace PXExtendCustomerToVendorExtPkg
{
    public class CustomerMaintPXExt : PXGraphExtension<CustomerMaint>
    {
        public PXAction<Customer> extendToVendorPXExt;
        [PXUIField(DisplayName = "Extend To Vendor Ext",
                   MapEnableRights = PXCacheRights.Select, 
                   MapViewRights = PXCacheRights.Select, 
                   Visible = false)]
        [PXButton]
        public virtual IEnumerable ExtendToVendorPXExt(PXAdapter adapter)
        {
            try
            {
                if (Base.extendToVendor.GetEnabled())
                    Base.extendToVendor.Press();
            }
            catch (Exception ex)
            {
                if (ex is PXRedirectRequiredException)
                {
                    PXRedirectRequiredException rdEx = (PXRedirectRequiredException)ex;
                    rdEx.Graph.Actions.PressSave();
                }
                else
                    throw ex;
            }
            return adapter.Get();
        }
    }
}

After publishing the customization, modify Import Scenario for Customers (SM206025) and add new Extend To Vendor Ext action after Save Action.

enter image description here

Download Customization Package

DChhapgar
  • 2,280
  • 12
  • 18
1

Very nice solution by DChhapgar. The below is modified version that works in Acumatica 21R1 since there were some modifications by Acumatica: respective ExtendToCustomer and ExtendToVendor PXGraphExtension(s) were created under:

App_Data\CodeRepository\PX.Objects\Extensions\ExtendBAccount enter image description here

Therefore there is a need to get extension first var graphExt = Base.GetExtension<ExtendToCustomer>();. Below code is used to extend to customer from BusinessAccount, which also makes some changes to customer prior to saving it (commented in code). The concept is the same for extending to vendor.

using PX.Data;
using PX.Objects.AR;
using System;
using System.Collections;
using static PX.Objects.CR.BusinessAccountMaint;

namespace PX.Objects.CR
{
    public class IBBusinessAccountMaintExt : PXGraphExtension<BusinessAccountMaint>
    {
        public PXAction<BAccount> extendToCustomerPXExt;
        [PXUIField(DisplayName = "Extend As Customer Ext", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Visible = false)]
        [PXButton]
        public virtual IEnumerable ExtendToCustomerPXExt(PXAdapter adapter)
        {
            try {
                var graphExt = Base.GetExtension<ExtendToCustomer>();
                if (graphExt.extendToCustomer.GetEnabled()) { graphExt.extendToCustomer.Press(); }
            } catch (Exception ex) {
                if (ex is PXRedirectRequiredException) {
                    PXRedirectRequiredException rdEx = (PXRedirectRequiredException)ex;
                    
                    // If there is a need to make changes in new Graph
                    CustomerMaint editCustomer = (CustomerMaint)rdEx.Graph;
                    //editCustomer.CurrentCustomer.SetValueExt<Customer.paymentsByLinesAllowed>(editCustomer.BAccount.Current, true);

                    rdEx.Graph.Actions.PressSave();
                } else
                    throw ex;
            }
            return adapter.Get();
        }
    }
}
Richard Mneyan
  • 656
  • 1
  • 13
  • 20