Skip to main content
Solved

How to Get Shipping Terms Field Value from Customers Screen Copied to Sales Order Header Custom Field


Forum|alt.badge.img+2

Hi I need to populate the value of the shipping terms field in the Customers screen into the sales order header in a custom field. How can I achieve this? This is my code so far.

[PXDBString(100)]
[PXDefault(typeof(Search<Location.cShipTermsID,
                          Where<Location.bAccountID, Equal<Current<SOOrder.bAccountID>>,
                          And<Location.locationID, Equal<Current<SOOrder.shipToLocationID>>>>),
            PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName="INCOTERMS")]

Please let me know if I’m implementing the right way, thank you!

Best answer by aiwan

Hi @TharidhiP 

 

You could use a field updated handler as an extension of the SOOrderEntry graph e.g.:

public class SOOrderShippingTermsExt : PXGrapchExtension<SOOrderEntry>
{

 protected virtual void _(Events.FieldUpdated<SOOrder, SOOrder.customerID> e)
{
 SOOrder row = e.Row;

 if(row == null) return;

 Location location = SelectFrom<Location>.
 Where<Location.BAccountID.IsEqual<P.AsInt>>.View.Select(Base, row.CustomerID)

 e.Cache.SetValueExt<SOOrder.yourCustomField>(row, location.YourReferenceField);

}

}

Hope this helps!

Aleks

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

2 replies

Forum|alt.badge.img+7
  • Captain II
  • 292 replies
  • Answer
  • August 9, 2024

Hi @TharidhiP 

 

You could use a field updated handler as an extension of the SOOrderEntry graph e.g.:

public class SOOrderShippingTermsExt : PXGrapchExtension<SOOrderEntry>
{

 protected virtual void _(Events.FieldUpdated<SOOrder, SOOrder.customerID> e)
{
 SOOrder row = e.Row;

 if(row == null) return;

 Location location = SelectFrom<Location>.
 Where<Location.BAccountID.IsEqual<P.AsInt>>.View.Select(Base, row.CustomerID)

 e.Cache.SetValueExt<SOOrder.yourCustomField>(row, location.YourReferenceField);

}

}

Hope this helps!

Aleks


Forum|alt.badge.img+2
  • Author
  • Semi-Pro II
  • 95 replies
  • August 14, 2024

Hi @aiwan thank you for the help! I tried using a field updated handler and now it works.

protected virtual void _(Events.FieldUpdated<SOOrder, SOOrder.customerID> e)
    {
        SOOrder row = e.Row as SOOrder;

        if (row == null) return;

        // Fetch Location using CustomerID
        PXResultset<Location> resultSet = PXSelectJoin<Location,
            InnerJoin<BAccount, On<BAccount.bAccountID, Equal<Location.bAccountID>>>,
            Where<BAccount.bAccountID, Equal<Required<BAccount.bAccountID>>>>
            .Select(Base, row.CustomerID);

        // Get the Location item from the result set
        Location location = resultSet?.FirstOrDefault();

        // Check if Location is found
        if (location != null)
        {


          // Get the SOOrder extension to access custom fields
            SOOrderExt rowExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(row);

            // Set the custom field with the value from Location's CShipTermsID
            rowExt.UsrShippingTermsINCOTERM = location.CShipTermsID;

            // Update the cache
            e.Cache.SetValueExt<SOOrderExt.usrShippingTermsINCOTERM>(row, rowExt.UsrShippingTermsINCOTERM);
        }
    }

 


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