I have some user-defined fields in the SOOrder form, when I convert that SO to the Shipment I want that fields to move to the Shipment form. How can I achieve this via customization.
Solved
Add UserDefined fields from SOOrder to Shipment
Best answer by Naveen Boga
The below code will work for you. Please verify.
public class SOOrderExt : PXCacheExtension<SOOrder>
{
[PXDBString(50, IsUnicode = true)]
[PXUIField(DisplayName = "Test Field")]
public string UsrTestField { get; set; }
public abstract class usrTestField : PX.Data.BQL.BqlString.Field<usrTestField> { }
}
public class SOShipmentExt : PXCacheExtension<SOShipment>
{
[PXDBString(50, IsUnicode = true)]
[PXUIField(DisplayName = "Test Field")]
public string UsrTestField { get; set; }
public abstract class usrTestField : PX.Data.BQL.BqlString.Field<usrTestField> { }
}
public class SOShipmentEntryExt : PXGraphExtension<SOShipmentEntry>
{
public delegate void PersistDelegate();
[PXOverride]
public void Persist(Action del)
{
if (Base.Document.Cache.GetStatus((object)Base.Document.Current) == PXEntryStatus.Inserted)
{
SOShipLine shipLine = Base.Transactions.Select().FirstTableItems.ToList().FirstOrDefault();
if (shipLine != null)
{
SOOrder objSOOrder = PXSelect<SOOrder, Where<SOOrder.orderType, Equal<Required<SOOrder.orderType>>,
And<SOOrder.orderNbr, Equal<Required<SOOrder.orderNbr>>>>>.Select(Base, shipLine.OrigOrderType, shipLine.OrigOrderNbr);
if (objSOOrder != null)
{
SOOrderExt orderExt = objSOOrder.GetExtension<SOOrderExt>();
SOShipmentExt shipmentExt = Base.Document.Current?.GetExtension<SOShipmentExt>();
shipmentExt.UsrTestField = orderExt.UsrTestField;
Base.Document.Cache.Update(Base.Document.Current);
}
}
}
del();
}
}
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.