Solved

Search Custom Field for PXUnboundDefault

  • 19 July 2023
  • 4 replies
  • 82 views

Userlevel 1
Badge

I’m trying to add the Sales Order Custom Field “UsrBoard” to the SOShipment DAC but I’m getting Object reference error:
 


namespace UsrSOBoard
{
public class SOShipmentExt : PXCacheExtension<PX.Objects.SO.SOShipment>
{
#region UsrCustomField
protected int _UsrSOBoard;

[PXDBInt]
[PXIntList(new int[] {0, 1}, new string[] {"WMS", "MTM"})]
[PXUIField(DisplayName = "Board")]
[PXUnboundDefault(typeof(Search<SOOrderExt.usrBoard,
Where<SOOrder.orderNbr, Equal<Current<SOLine.orderNbr>>,
And<SOOrder.orderType, Equal<Current<SOLine.orderType>>>>>))]
public virtual int UsrSOBoard
{
get
{
return _UsrSOBoard;
}
set
{
_UsrSOBoard = value;
}
}
public abstract class usrSOBoard : IBqlField { }
#endregion
}
}

 

icon

Best answer by Leonardo Justiniano 19 July 2023, 07:00

View original

4 replies

Userlevel 6
Badge +4

Hi @jayson 

The field you are adding is database bound because you are using PXDBInt. Therefore, the value will be stored in the SOShipment table and you do not need retrieve the value via PXUnboundDefault

    [PXUnboundDefault(typeof(Search<SOOrderExt.usrBoard,
Where<SOOrder.orderNbr, Equal<Current<SOLine.orderNbr>>,
And<SOOrder.orderType, Equal<Current<SOLine.orderType>>>>>))]

PXUnboundDefault is used to default unbound columns if you want to execute the query during the fetch of the record, for each record. A more efficient way to do it is using PXDBScalar.

 

I would simplify the class as follow:

namespace MyCustom
{
public class SOShipmentExt : PXCacheExtension<PX.Objects.SO.SOShipment>
{
#region UsrSOBoard

[PXDBInt]
[PXIntList(new int[] {0, 1}, new string[] {"WMS", "MTM"})]
[PXUIField(DisplayName = "Board")]
public virtual int? UsrSOBoard { get; set; }

public abstract class usrSOBoard : BqlType<IBqlInt, int>.Field<usrSOBoard> { }

#endregion
}
}

Make sure you added the custom field to the table in the Custom Package:

Database Scripts

 

Hope this can help

Userlevel 1
Badge

Hi @jayson 

The field you are adding is database bound because you are using PXDBInt. Therefore, the value will be stored in the SOShipment table and you do not need retrieve the value via PXUnboundDefault

    [PXUnboundDefault(typeof(Search<SOOrderExt.usrBoard,
Where<SOOrder.orderNbr, Equal<Current<SOLine.orderNbr>>,
And<SOOrder.orderType, Equal<Current<SOLine.orderType>>>>>))]

PXUnboundDefault is used to default unbound columns if you want to execute the query during the fetch of the record, for each record. A more efficient way to do it is using PXDBScalar.

 

I would simplify the class as follow:

namespace MyCustom
{
public class SOShipmentExt : PXCacheExtension<PX.Objects.SO.SOShipment>
{
#region UsrSOBoard

[PXDBInt]
[PXIntList(new int[] {0, 1}, new string[] {"WMS", "MTM"})]
[PXUIField(DisplayName = "Board")]
public virtual int? UsrSOBoard { get; set; }

public abstract class usrSOBoard : BqlType<IBqlInt, int>.Field<usrSOBoard> { }

#endregion
}
}

Make sure you added the custom field to the table in the Custom Package:

Database Scripts

 

Hope this can help

What I really want to do is to be able to add “Board” a custom field of Sales order into Process Shipments just like this one:
 

 

Userlevel 6
Badge +4

Hi @jayson 

 

 Please declare the field unbound as follow and add the following query:

namespace MyCustom
{
public sealed class SOShipmentExt : PXCacheExtension<SOShipment>
{
#region UsrSOBoard

[PXInt]
[PXIntList(new int[] { 0, 1 }, new string[] { "WMS", "MTM" })]
[PXUIField(DisplayName = "Board")]
[PXDBScalar(typeof(Search2<SOOrderExt.usrBoard,
InnerJoin<SOOrderShipment,
On<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>,
And<SOOrder.orderType, Equal<SOOrderShipment.orderType>>>>,
Where<SOOrderShipment.shipmentNbr, Equal<Current<SOShipment.shipmentNbr>>>>))]
public int? UsrSOBoard { get; set; }

public abstract class usrSOBoard : BqlType<IBqlInt, int>.Field<usrSOBoard> { }

#endregion
}
}

The missing piece is the link between the two.

Userlevel 1
Badge

Hi @jayson 

 

 Please declare the field unbound as follow and add the following query:

namespace MyCustom
{
public sealed class SOShipmentExt : PXCacheExtension<SOShipment>
{
#region UsrSOBoard

[PXInt]
[PXIntList(new int[] { 0, 1 }, new string[] { "WMS", "MTM" })]
[PXUIField(DisplayName = "Board")]
[PXDBScalar(typeof(Search2<SOOrderExt.usrBoard,
InnerJoin<SOOrderShipment,
On<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>,
And<SOOrder.orderType, Equal<SOOrderShipment.orderType>>>>,
Where<SOOrderShipment.shipmentNbr, Equal<Current<SOShipment.shipmentNbr>>>>))]
public int? UsrSOBoard { get; set; }

public abstract class usrSOBoard : BqlType<IBqlInt, int>.Field<usrSOBoard> { }

#endregion
}
}

The missing piece is the link between the two.

Thank you so much! I just changed PXDBScalar to PXUnboundDefault in your code and it is working perfectly now.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved