Skip to main content
Answer

Search Custom Field for PXUnboundDefault

  • July 19, 2023
  • 4 replies
  • 186 views

Forum|alt.badge.img

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
}
}

 

Best answer by Leonardo Justiniano

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.

4 replies

Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+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


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • July 19, 2023

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:
 

 


Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+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.


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • July 20, 2023

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.