Skip to main content
Answer

How to access Customer User-Defined Field in a new Processing screen View Delegate

  • May 17, 2023
  • 4 replies
  • 492 views

vivekm
Varsity II
Forum|alt.badge.img

Hi Team,

I have create a new processing screen and in view delegate trying to access a Use Defined Field value from Customer screen to show on UI and I am using 22.106.0015 build version.

 

I have referred some community posts but not been able to access the defined field value. Below are the samples I have verified:

 public sealed class SOLineExt : PXCacheExtension<SOLine>
    {
        public static bool IsActive() { return true; }

 #region UsrEmployer
        [PXString()]
        [PXUIField(DisplayName = "Employer")]
        public string UsrEmployer { get; set; }
        public abstract class usrEmployer : PX.Data.BQL.BqlString.Field<usrEmployer> { }
        #endregion

}

 

public class LineProcessMaint : PXGraph<LineProcessMaint>
    {
        #region Views
        public PXCancel<SOLine> Cancel;
        public PXProcessing<SOLine> KitAssemblyProcess;

        #endregion
        
        protected IEnumerable kitAssemblyProcess()
        {
        foreach (PXResult<SOLine, SOOrder, SOShippingContact, InventoryItem> result in PXSelectJoin<SOLine, InnerJoin<SOOrder, On<SOOrder.orderType, Equal<SOLine.orderType>, And<SOOrder.orderNbr, Equal<SOLine.orderNbr>>>,
                                            InnerJoin<SOShippingContact, On<SOShippingContact.contactID, Equal<SOOrder.shipContactID>>,
                                            InnerJoin<InventoryItem, On<InventoryItem.inventoryID, Equal<SOLine.inventoryID>>>>>,
                                            Where<InventoryItem.kitItem, Equal<True>>, OrderBy<Desc<SOLine.orderNbr>>>.Select(this))
            {
            SOLine line = result;
                SOOrder order = result;
                SOShippingContact shippingContact = result;
                InventoryItem inv = result;       
                SOLineExt lineExt = line?.GetExtension<SOLineExt>();
                 BAccount bAccount = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Required<BAccount.bAccountID>>>>.Select(this, order?.CustomerID);
                PXCache cache = base.Caches[typeof(BAccount)];
                var attributeEMPLOYER = (PXStringState)cache.GetValueExt(bAccount, "AttributeEMPLOYER");

                
                 lineExt.UsrEmployer = attributeEMPLOYER;
            }
        }
        
        }

 

Can you please review and help, Thank you in Advance !

Best answer by Naveen Boga

@vivekm  I have not verified this but can you try like below and verify.  

 public class LineProcessMaint : PXGraph<LineProcessMaint>
{
#region Views
public PXCancel<SOLine> Cancel;
public PXProcessing<SOLine> KitAssemblyProcess;

#endregion

protected IEnumerable kitAssemblyProcess()
{
CustomerMaint customerGraph = PXGraph.CreateInstance<CustomerMaint>();
foreach (PXResult<SOLine, SOOrder, SOShippingContact, InventoryItem> result in PXSelectJoin<SOLine, InnerJoin<SOOrder, On<SOOrder.orderType, Equal<SOLine.orderType>, And<SOOrder.orderNbr, Equal<SOLine.orderNbr>>>,
InnerJoin<SOShippingContact, On<SOShippingContact.contactID, Equal<SOOrder.shipContactID>>,
InnerJoin<InventoryItem, On<InventoryItem.inventoryID, Equal<SOLine.inventoryID>>>>>,
Where<InventoryItem.kitItem, Equal<True>>, OrderBy<Desc<SOLine.orderNbr>>>.Select(this))
{
customerGraph.Clear();
SOLine line = result;
SOOrder order = result;
SOShippingContact shippingContact = result;
InventoryItem inv = result;
SOLineExt lineExt = line?.GetExtension<SOLineExt>();

customerGraph.BAccount.Current = PXSelect<Customer, Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>.Select(this, order?.CustomerID);

var row = customerGraph.BAccount.Current;
var cache = customerGraph.BAccount.Cache;

var attributeEMPLOYER = (PXStringState)cache.GetValueExt(bAccount, "AttributeEMPLOYER");

lineExt.UsrEmployer = attributeEMPLOYER;
}
}

}

 

4 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • Answer
  • May 17, 2023

@vivekm  I have not verified this but can you try like below and verify.  

 public class LineProcessMaint : PXGraph<LineProcessMaint>
{
#region Views
public PXCancel<SOLine> Cancel;
public PXProcessing<SOLine> KitAssemblyProcess;

#endregion

protected IEnumerable kitAssemblyProcess()
{
CustomerMaint customerGraph = PXGraph.CreateInstance<CustomerMaint>();
foreach (PXResult<SOLine, SOOrder, SOShippingContact, InventoryItem> result in PXSelectJoin<SOLine, InnerJoin<SOOrder, On<SOOrder.orderType, Equal<SOLine.orderType>, And<SOOrder.orderNbr, Equal<SOLine.orderNbr>>>,
InnerJoin<SOShippingContact, On<SOShippingContact.contactID, Equal<SOOrder.shipContactID>>,
InnerJoin<InventoryItem, On<InventoryItem.inventoryID, Equal<SOLine.inventoryID>>>>>,
Where<InventoryItem.kitItem, Equal<True>>, OrderBy<Desc<SOLine.orderNbr>>>.Select(this))
{
customerGraph.Clear();
SOLine line = result;
SOOrder order = result;
SOShippingContact shippingContact = result;
InventoryItem inv = result;
SOLineExt lineExt = line?.GetExtension<SOLineExt>();

customerGraph.BAccount.Current = PXSelect<Customer, Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>.Select(this, order?.CustomerID);

var row = customerGraph.BAccount.Current;
var cache = customerGraph.BAccount.Cache;

var attributeEMPLOYER = (PXStringState)cache.GetValueExt(bAccount, "AttributeEMPLOYER");

lineExt.UsrEmployer = attributeEMPLOYER;
}
}

}

 


vivekm
Varsity II
Forum|alt.badge.img
  • Author
  • Varsity II
  • May 18, 2023

Hi @Naveen Boga thank you for the details. 

I also verified with same and it worked as expected but the only concern I have with this approach is the Customer Graph Initialization. As we are working with view delegate, so the graph initialization may delay the data load significantly. 

Can you please suggest if there is another way to achieve this.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • May 18, 2023

Hi @vivekm  Yes, I too have this my mind but I don’t think we have another approach to fetch the UDF field value.

But I suggest an alternate solution for your customization to avoid the performance issue, check if this can works for you.

You can have the internal field for the UDF field in the SOOrder Extension, and add logic to when UDF is added, your internal field should be updated accordingly. For old records, you can run a script.

So that, in this processing you can fetch the field value simply from SOOrder DAC.

 

Hope this helps!


vivekm
Varsity II
Forum|alt.badge.img
  • Author
  • Varsity II
  • May 18, 2023

Thank you for the details @Naveen Boga 

Sure, I can check with that.