Solved

How to get the default value for the Transaction Period and Financial Period

  • 8 December 2021
  • 18 replies
  • 750 views

Userlevel 7
Badge +8

How to get the default value for the Transaction Period and Financial Period based on a date field entered and branch selector

 

Hello,

I have a customization form that I need to fill “Transaction Period” and company’s “Financial Period” by defult from a date field and the selected branch but I can not make it work. I reviewed a couple Acumatica’s owen screens and I’m doing exctly the same (at least I think so) but these two fields are not filled by default. Any help appreciated. Here is my little Graph, partial DAC and Partial ASPX.

 

namespace MyCustom

}

    // Graph

    public class PMCashflowProjectionEntry : PXGraph<PMCashflowProjectionEntry, PMCashflowProjection>

    {

 

        [PXViewName("Projects Cashflow Projections")]

        public PXSelect<PMCashflowProjection> CashflowProjections;

 

        public PXSelect<PMCashflowProjectionSchedule, Where<PMCashflowProjectionSchedule.projectID, Equal<Current<PMCashflowProjection.projectID>>>> CashflowProjectionSchedules;

 

    }

 

    //Partial Header DAC

    public class PMCashflowProjection : IBqlTable

    {

        #region BranchID

        public abstract class branchID : PX.Data.BQL.BqlInt.Field<branchID> { }

        protected Int32? _BranchID;

        [Branch()]

        [PXForeignReference(typeof(Field<branchID>.IsRelatedTo<Branch.branchID>))]

        [PXUIField(DisplayName = "Branch", Visibility = PXUIVisibility.SelectorVisible, Required = true, Enabled = true, Visible = true)]

        public virtual Int32? BranchID

        {

            get

            {

                return this._BranchID;

            }

            set

            {

                this._BranchID = value;

            }

        }

        #endregion

 

    }

 

    //Partial Detail DAC

    public class PMCashflowProjectionSchedule : IBqlTable

    {

        #region Date

        public abstract class date : PX.Data.BQL.BqlDateTime.Field<date> { }

        protected DateTime? _Date;

        [PXDBDate()]

        [PXDefault(typeof(AccessInfo.businessDate), PersistingCheck = PXPersistingCheck.Nothing)]

        [PXUIField(DisplayName = "Date", Visibility = PXUIVisibility.SelectorVisible, Required = true, Enabled = true, Visible = true, IsReadOnly = false)]

        public virtual DateTime? Date

        {

            get

            {

                return this._Date;

            }

            set

            {

                this._Date = value;

            }

        }

        #endregion

 

        #region TranPeriodID

        public abstract class tranPeriodID : PX.Data.BQL.BqlString.Field<tranPeriodID> { }

        protected String _TranPeriodID;

        [PXDefault()]

        [PeriodID(

            searchType: null,

            sourceType: typeof(date),

            defaultType: null,

            redefaultOnDateChanged: true)]

        [PXUIField(DisplayName = "Tran. Period", Visibility = PXUIVisibility.SelectorVisible, Required = true, Enabled = true, Visible = true)]

        public virtual String TranPeriodID

        {

            get

            {

                return this._TranPeriodID;

            }

            set

            {

                this._TranPeriodID = value;

            }

        }

        #endregion

 

        #region FinPeriodID

        public abstract class finPeriodID : PX.Data.BQL.BqlString.Field<finPeriodID> { }

        protected String _FinPeriodID;

        [PXDefault()]

        [FinPeriodID(

            sourceType: typeof(date),

            branchSourceType: typeof(PMCashflowProjection.branchID),

            masterFinPeriodIDType: typeof(tranPeriodID),

            headerMasterFinPeriodIDType: typeof(tranPeriodID),

            redefaultOnDateChanged: true)]

        [PXUIField(DisplayName = "Fin. Period", Visibility = PXUIVisibility.SelectorVisible, Required = true, Enabled = true, Visible = true)]

        public virtual String FinPeriodID

        {

            get

            {

                return this._FinPeriodID;

            }

            set

            {

                this._FinPeriodID = value;

            }

        }

        #endregion

    }

}

 

{

    //Partial ASPX

    //Form

 

            <px:PXSegmentMask runat="server" ID="edBranchID" DataField="BranchID" CommitChanges="True" AutoRefresh="True" />


 

    //Grid Clumns

            <px:PXGridColumn DataField="Date" Width="80" CommitChanges="True" ></px:PXGridColumn>

            <px:PXGridColumn DataField="TranPeriodID" Width="80" CommitChanges="True" ></px:PXGridColumn>

            <px:PXGridColumn DataField="FinPeriodID" Width="80" CommitChanges="True" ></px:PXGridColumn>

 

    // Grid Row Template

            <px:PXDateTimeEdit runat="server" ID="edDate" DataField="Date" CommitChanges="True" AutoRefresh="True" ></px:PXDateTimeEdit>

            <px:PXMaskEdit runat="server" ID="edTranPeriodID" DataField="TranPeriodID" CommitChanges="True" Size="s" ></px:PXMaskEdit>

            <px:PXMaskEdit runat="server" ID="edFinPeriodID" DataField="FinPeriodID" CommitChanges="True" Size="s" ></px:PXMaskEdit>

 

}

icon

Best answer by aaghaei 11 December 2021, 06:47

View original

18 replies

Userlevel 7
Badge +17

Hi @aaghaei  Below is the sample code your reference. Hope this helps!

#region FinPeriodID
public abstract class finPeriodID : PX.Data.BQL.BqlString.Field<finPeriodID> { }
protected String _FinPeriodID;

[FinPeriodID(
branchSourceType: typeof(PMCashflowProjectionSchedule.branchID),
masterFinPeriodIDType: typeof(PMCashflowProjectionSchedule.tranPeriodID),
headerMasterFinPeriodIDType: typeof(PMCashflowProjection.tranPeriodID))]
public virtual String FinPeriodID
{
get
{
return this._FinPeriodID;
}
set
{
this._FinPeriodID = value;
}
}
#endregion


#region TranPeriodID
public abstract class tranPeriodID : PX.Data.BQL.BqlString.Field<tranPeriodID> { }
[PeriodID]
public virtual String TranPeriodID { get; set; }
#endregion

 

Userlevel 7
Badge +8

Thanks @Naveen B for the response. I see you have assumed that parent DAC has FinPeriodID and child DAC has  branchID but in my case it is exactly opposit. considering all child records will tie to one branch. branchID is on parent and also considering each child item can have a different date, FinPeriodID is only on the child. how can I make this work?

Userlevel 7
Badge +17

Hi @aaghaei  That is exactly we need to pass the details to FinPeriod attribute at DAC level.

There is another way, to assign the FinPeriod from the code level. You can write a FieldDefaulting event with below code to get the Financial Period.

 

   var finperiod = Graph.FinPeriodRepository.GetPeriodIDFromDate
(filterDate, PXAccess.GetParentOrganizationID
(new DRRecognition().Filter.Current.BranchID));

I used this code in one of my projects and it worked well.

 

Hope this helps!

Userlevel 7
Badge +8

Thanks @Naveen B . I tried this as well but couldn’t figure out why i’m getting error FinPeriodRepository and filterDate. Here is my graph:

   public class PMCashflowProjectionEntry : PXGraph<PMCashflowProjectionEntry, PMCashflowProjection>
    {

        [PXViewName("Projects Cashflow Projections")]
        public PXSelect<PMCashflowProjection> CashflowProjections;

        public PXSelect<PMCashflowProjectionSchedule, Where<PMCashflowProjectionSchedule.projectID, Equal<Current<PMCashflowProjection.projectID>>>> CashflowProjectionSchedules;

        public PXFilter<PMCashflowProjection> ProjectionFilter;
        public PXFilter<PMCashflowProjectionSchedule> ScheduleFilter;
        public IFinPeriodRepository FinPeriodRepository { get; set; }

        #region Event Handlers
        protected void PMCashflowProjectionSchedule_FinPeriodID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
        {
            var row = (PMCashflowProjectionSchedule)e.Row;
            if (row == null) return;
            var finperiod = Graph.FinPeriodRepository.GetPeriodIDFromDate
                                      (filterDate, PXAccess.GetParentOrganizationID
                                      (new PMCashflowProjectionEntry().ProjectionFilter.Current.BranchID));
        }
        #endregion
 

Userlevel 7
Badge +17

@aaghaei  Please use below code and verify

 #region Event Handlers
protected void PMCashflowProjectionSchedule_FinPeriodID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
var row = (PMCashflowProjectionSchedule)e.Row;
if (row == null) return;
PX.Objects.DR.ScheduleMaint scheduleMaint = PXGraph.CreateInstance<PX.Objects.DR.ScheduleMaint>();
var finperiod = scheduleMaint.FinPeriodRepository.GetPeriodIDFromDate
(this.Accessinfo.BusinessDate, PXAccess.GetParentOrganizationID
(ProjectionFilter.Current.BranchID));
}
#endregion

 

Userlevel 7
Badge +8

Thanks @Naveen B still I have one issue and one clarification. The issue is you are using “Deferred Revenue” module that we do not have it. Any alternative option? The clarfication is instead of “this.Accessinfo.BusinessDate” I should use “ScheduleFilter.Current.Date” as I need the date from line i’m entering not from the business date. Correct?

 

            var finPeriod = scheduleMaint.FinPeriodRepository.GetPeriodIDFromDate
                            (ScheduleFilter.Current.Date, PXAccess.GetParentOrganizationID
                            (ProjectionFilter.Current.BranchID));

            row.FinPeriodID = finPeriod;

Userlevel 7
Badge +17

Hi @aaghaei  Yes, we have alternate option, here is the code.

   private IFinPeriodRepository _finPeriodRepository;  // Declare this as Global variable --> Namespace (using PX.Objects.GL.FinPeriods;)


var finPeriod = FinPeriodRepository.GetPeriodIDFromDate
(ScheduleFilter.Current.Date, PXAccess.GetParentOrganizationID
(ProjectionFilter.Current.BranchID));

Instead of “this.Accessinfo.BusinessDate you can use “ScheduleFilter.Current.Date” field value.

Userlevel 7
Badge +8

Thanks @Naveen B , Still doesn’t work. interestingly it takes away the values that by default previously was set in “Schedule” grid including ProjectID and Date.“using PX.Objects.GL.FinPeriods;” was already included in my code. Here is my complete Graph.

public class PMCashflowProjectionEntry : PXGraph<PMCashflowProjectionEntry, PMCashflowProjection>
{
[PXViewName("Projects Cashflow Projections")]
public PXSelect<PMCashflowProjection> CashflowProjections;

public PXSelect<PMCashflowProjectionSchedule, Where<PMCashflowProjectionSchedule.projectID, Equal<Current<PMCashflowProjection.projectID>>>> CashflowProjectionSchedules;

public PXFilter<PMCashflowProjection> ProjectionFilter;
public PXFilter<PMCashflowProjectionSchedule> ScheduleFilter;

//public IFinPeriodRepository FinPeriodRepository { get; set; }
private IFinPeriodRepository _FinPeriodRepository;

#region Event Handlers
protected void PMCashflowProjectionSchedule_FinPeriodID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
var row = (PMCashflowProjectionSchedule)e.Row;
if (row == null) return;

var finPeriod = _FinPeriodRepository.GetPeriodIDFromDate
(ScheduleFilter.Current.Date, PXAccess.GetParentOrganizationID
(ProjectionFilter.Current.BranchID));

row.FinPeriodID = finPeriod;
}
#endregion
}

 

 

 

Userlevel 7
Badge +17

Hi @aaghaei  Did you debug and verified that below fields are hold the values?

  • ScheduleFilter.Current.Date 
  • ProjectionFilter.Current.BranchID

 

 

Userlevel 7
Badge +8

Yes, When I’m not adding fielddefaulting event, both of the fields you question about have values as are defined on the DAC. When I add field defaulting event not sure why “ProjectionFilter.Current.BranchID” has value but “ScheduleFilter.Current.Date” is null.

Userlevel 7
Badge +17

Since this field is NULL, hence Financial Period will be empty.

You need to pass the both field value, then only you can able to fetch the Fin period.

 

In the DAC you can use PXDefault(typeof(Accessinfo.businessdate)) and verify.

Userlevel 7
Badge +8

It is already in my DAC. here is date field properties

        [PXDBDate()]
        [PXDefault(typeof(AccessInfo.businessDate), PersistingCheck = PXPersistingCheck.Nothing)]
        [PXUIField(DisplayName = "Date", Visibility = PXUIVisibility.SelectorVisible, Required = true, Enabled = true, Visible = true, IsReadOnly = false)]
 

Userlevel 7
Badge +17

Do you have CommitChanges = True for those fields at .aspx page ?

Userlevel 7
Badge +8

Yes @Naveen B , please see below partial ASPX for form and grid

form partial:

	<px:PXFormView ID="form" runat="server" DataSourceID="ds" Style="z-index: 100" Width="100%" Height="150px" AllowAutoHide="true" DataMember="CashflowProjections">
<Template>
<px:PXLayoutRule runat="server" ID="PXLayoutRule1" StartColumn="True" ControlSize="XM" LabelsWidth ="SM" ></px:PXLayoutRule>
<px:PXSegmentMask runat="server" ID="edProjectID" DataField="ProjectID" CommitChanges="True" AutoRefresh="true" ></px:PXSegmentMask>
<px:PXSegmentMask runat="server" ID="edBranchID" DataField="BranchID" CommitChanges="True" AutoRefresh="True" />

 

grid row template partial

                                <RowTemplate>
<px:PXLayoutRule runat="server" StartColumn="True" ControlSize="XM" LabelsWidth="SM" ></px:PXLayoutRule>
<px:PXNumberEdit runat="server" ID="edScheduleID" DataField="ScheduleID" CommitChanges="True" Enabled="false" ></px:PXNumberEdit>
<px:PXSegmentMask runat="server" ID="edProjectID" DataField="ProjectID" CommitChanges="True" AutoRefresh="True" ></px:PXSegmentMask>
<px:PXDateTimeEdit runat="server" ID="edDate" DataField="Date" CommitChanges="True" ></px:PXDateTimeEdit>
<px:PXMaskEdit runat="server" ID="edTranPeriodID" DataField="TranPeriodID" CommitChanges="True" Size="s" ></px:PXMaskEdit>
<px:PXMaskEdit runat="server" ID="edFinPeriodID" DataField="FinPeriodID" CommitChanges="True" Size="s" ></px:PXMaskEdit>

 

and grid column partial

								<Columns>
<px:PXGridColumn DataField="ScheduleID" Width="140" CommitChanges="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="ProjectID" Width="80" CommitChanges="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="Date" Width="80" CommitChanges="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="TranPeriodID" Width="80" CommitChanges="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="FinPeriodID" Width="80" CommitChanges="True" ></px:PXGridColumn>

 

Userlevel 7
Badge

Hi @Naveen B any other ideas for @aaghaei ? Thanks!

Userlevel 7
Badge +8

@Chris Hackett  and @Naveen B thanks for the support.  I figured it out. The problem was not the DAC. For some reason when we set CommitChanges = True on Date anf FinPeriodID it causes problem instead I changed it to AutoCallBack = True and works fine no need to manupulate the graph events.

<px:PXGridColumn DataField="TranDate" AutoCallBack="True" Width="70" />
<px:PXGridColumn DataField="FinPeriodID" AutoCallBack="True" Width="70" />
<px:PXGridColumn DataField="TranPeriodID" CommitChanges="True" Width="70" />

 

Userlevel 7
Badge +17

@aaghaei  Since this is a just grid field CommitChanges =“True” should work, but NOT sure why it is not working in your case.

 

Userlevel 7
Badge +8

@Naveen B I agree but i’m not sure about the rootcause either.

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