Skip to main content

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!

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


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