Skip to main content
Answer

How to Update customized fields from SubContract Line to Bills and Adjustment Line while creating AP Bills from SubContract

  • November 28, 2021
  • 4 replies
  • 143 views

Forum|alt.badge.img

2

Hi All,

I have  2 customized fields in subcontract Lines. while creating AP bills from subcontract I want to carry forward this field values to another custom field in Bills and Adjustment Line. I tried to achieve this through “CreateAPInvoice” override method in Subcontract ,  but i’m not sure how to execute this correctly below are my incomplete lines of code. Could anyone please help me on this.

 

 

Regards,

Ramya

Best answer by Naveen Boga

Hi @ramya15   We can achieve your requirement using [PXDefault()] attribute. 

Below code I have verified, with join conditions and it is fetching the data properly from Subcontracts screen to Bills and Adjustments screen.

 

Please find the code samples below, which you are looking for. Hope this helps! 

Let me know if this is working for you as well.

 public sealed class ARTranExt : PXCacheExtension<ARTran>
    {
        #region UsrLADperDay

        [PXDBDecimal()]
        [PXDefault(typeof(Search<POLineExt.usrLADperDay,
                Where<POLine.orderType, Equal<Current<APTran.pOOrderType>>,
                And<POLine.orderNbr, Equal<Current<APTran.pONbr>>,
                And<POLine.lineNbr, Equal<Current<APTran.pOLineNbr>>>>>>),
        PersistingCheck = PXPersistingCheck.Nothing)]
        [PXUIField(DisplayName = "LAD Per Day")]
        public virtual decimal? UsrLADperDay { get; set; }
        public abstract class usrLADperDay : PX.Data.BQL.BqlDecimal.Field<usrLADperDay> { }


        #region UsrLADAmount

        [PXDBDecimal()]
        [PXDefault(typeof(Search<POLineExt.usrLADAmount,
                Where<POLine.orderType, Equal<Current<APTran.pOOrderType>>,
                And<POLine.orderNbr, Equal<Current<APTran.pONbr>>,
                And<POLine.lineNbr, Equal<Current<APTran.pOLineNbr>>>>>>),
        PersistingCheck = PXPersistingCheck.Nothing)]
        [PXUIField(DisplayName = "LAD Amount")]
        public virtual decimal? UsrLADAmount { get; set; }
        public abstract class usrLADAmount : PX.Data.BQL.BqlDecimal.Field<usrLADAmount> { }

    }

 

4 replies

jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • November 28, 2021

Hi @ramya15 

Please find the ways to deriving Values of Custom Fields 

Ways:
1. Override methods that are used to create child record
2. Use events
3. Use the PXDefault attribute 

Example:

Use of Methods

[PXOverride]
public virtual ARTran CreateTranFromShipLine(...)
{
    ARTran tran = baseMethod(newdoc, ordertype, operation, orderline, ref shipline);
 
    SOLine line = PXSelect<SOLine,
        Where<SOLine.orderType, Equal<Required<SOLine.orderType>>,
        And<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>,
        And<SOLine.lineNbr, Equal<Required<SOLine.lineNbr>>>>>>
        .Select(Base, orderline.OrderType, orderline.OrderNbr, orderline.LineNbr);
 
    var value = Base.Caches[typeof(SOLine)].GetValue<SOLineExt.isDeductible>(line);
    Base.Caches[typeof(ARTran)].SetValue<ARTranExt.isDeductible>(tran, value);
    return tran;
}


Use of Events

public virtual void ARTran_IsDeductible_FieldDefaulting(...)
{
    ARTran tran = (ARTran)e.Row;
 
    SOLine line = PXSelect<SOLine,
        Where<SOLine.orderType, Equal<Required<SOLine.orderType>>,
        And<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>,
        And<SOLine.lineNbr, Equal<Required<SOLine.lineNbr>>>>>>
            .Select(Base, tran.SOOrderType, tran.SOOrderNbr, tran.SOOrderLineNbr);
            
    e.NewValue = Base.Caches[typeof(SOLine)].GetValue<SOLineExt.isDeductible>(line);
}

Use of PXDefaultAttribute

public sealed class ARTranExtAttributes : PXCacheExtension<ARTran>
{
    #region IsDeductible
    public abstract class isDeductible : IBqlField { }
    [PXDBBool]
    [PXDefault(typeof(Search<SOLineExt.isDeductible,
            Where<SOLine.orderType, Equal<ARTran.sOOrderType>,
            And<SOLine.orderNbr, Equal<ARTran.sOOrderNbr>,
            And<SOLine.lineNbr, Equal<ARTran.sOOrderLineNbr>>>>>),
    PersistingCheck = PXPersistingCheck.Nothing)]
    [PXUIField(DisplayName = "Deductible", Visible = true)]
    public bool? IsDeductible
    {
        get;
        set;
    }
 

Hope this help you.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • Answer
  • November 28, 2021

Hi @ramya15   We can achieve your requirement using [PXDefault()] attribute. 

Below code I have verified, with join conditions and it is fetching the data properly from Subcontracts screen to Bills and Adjustments screen.

 

Please find the code samples below, which you are looking for. Hope this helps! 

Let me know if this is working for you as well.

 public sealed class ARTranExt : PXCacheExtension<ARTran>
    {
        #region UsrLADperDay

        [PXDBDecimal()]
        [PXDefault(typeof(Search<POLineExt.usrLADperDay,
                Where<POLine.orderType, Equal<Current<APTran.pOOrderType>>,
                And<POLine.orderNbr, Equal<Current<APTran.pONbr>>,
                And<POLine.lineNbr, Equal<Current<APTran.pOLineNbr>>>>>>),
        PersistingCheck = PXPersistingCheck.Nothing)]
        [PXUIField(DisplayName = "LAD Per Day")]
        public virtual decimal? UsrLADperDay { get; set; }
        public abstract class usrLADperDay : PX.Data.BQL.BqlDecimal.Field<usrLADperDay> { }


        #region UsrLADAmount

        [PXDBDecimal()]
        [PXDefault(typeof(Search<POLineExt.usrLADAmount,
                Where<POLine.orderType, Equal<Current<APTran.pOOrderType>>,
                And<POLine.orderNbr, Equal<Current<APTran.pONbr>>,
                And<POLine.lineNbr, Equal<Current<APTran.pOLineNbr>>>>>>),
        PersistingCheck = PXPersistingCheck.Nothing)]
        [PXUIField(DisplayName = "LAD Amount")]
        public virtual decimal? UsrLADAmount { get; set; }
        public abstract class usrLADAmount : PX.Data.BQL.BqlDecimal.Field<usrLADAmount> { }

    }

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • November 29, 2021

Thanks @Naveen B and @jinin 

Both logics are working. Thank you so much.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • November 29, 2021

@ramya15 Great, Thanks for sharing the update.