Skip to main content
Solved

Check Box Customization


Forum|alt.badge.img

In acumatica project screen(PM301000) i have add two custome fields. those are UsrOnBudget and UsrCompletedPrec. i need to develop when i check UsrOnBudget check box get PMRevenueBudget.CuryAmount and divide by PMCostBudget.CuryAmount And that value show on UsrCompletedPrec field. Those To Customized Field locate in CT.ContractExt. How can I achieve it?

Best answer by aaghaei

@tharinduweerasooriya90  I can see two issues in your code

  1. In the Field Updated Event Handler I see the first parameter is missing. It should be something like _(Events.FieldUpdated<Contract, ContractExt.usrOnBudget> e) 
  2. In CalculateCompletedPerc your las line of code is never going to be executed as you are returning anyways before that point.

Also I suggest

  1. move your decimal percentage = (actualCostQty / actualRevenueAmount) * 100; into the if so you won’t get error in case you have actualRevenueAmount zero.
  2. assign either zero or your calculated formula to a variable and return at the end of your method
  3. Use Base.Projects.Update(contract) as you already have it initiated in the Base.
  4. Instead of using LINQ you can use GroupBy <AggregateTo<Sum<YourField>>> and tally your project revenue and cost.
View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img

This is my code. actualRevenueAmount and actualCostQty  assigned their value as actualRevenueAmount + actualCostQty . Not give correct output

ex: PMRevenueBudget.CuryAmount = 20

      PMCostBudget.CuryAmount = 10

 

      actualRevenueAmount = 30

      actualCostQty = 30

using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using PX.Objects.CA;
using PX.Objects.CT;
using PX.Objects.PM;
using System.Linq;

namespace Lauges
{
    public class ProjectEntryExt : PXGraphExtension<ProjectEntry>
    {
        #region Event Handlers

        protected void _(Events.FieldUpdated<ContractExt.usrOnBudget> e)
        {
            var row = e.Row as Contract;


            if (row != null && (bool)e.NewValue == true)
            {
                CalculateCompletedPerc(row);

            }
        }

        private decimal CalculateCompletedPerc(Contract contract)
        {


            decimal actualRevenueAmount = PXSelect<PMRevenueBudget,
                Where<PMRevenueBudget.projectID, Equal<Current<Contract.contractID>>>>
                .Select(Base).FirstTableItems.Sum(rb => rb.CuryAmount ?? 0);


            decimal actualCostQty = PXSelect<PMCostBudget,
                Where<PMCostBudget.projectID, Equal<Current<Contract.contractID>>>>
                .Select(Base).FirstTableItems.Sum(cb => cb.CuryAmount ?? 0);


            decimal percentage = (actualCostQty / actualRevenueAmount) * 100;

            if (actualRevenueAmount != 0)
            {
                contract.GetExtension<ContractExt>().UsrCompletedPercentage = percentage;

                return percentage;
            }
            else
            {

                return 0;
            }

            Base.Caches[typeof(Contract)].Update(contract);

        }

        #endregion
    }
}

 


aaghaei
Captain II
Forum|alt.badge.img+9
  • Captain II
  • 1178 replies
  • Answer
  • May 17, 2024

@tharinduweerasooriya90  I can see two issues in your code

  1. In the Field Updated Event Handler I see the first parameter is missing. It should be something like _(Events.FieldUpdated<Contract, ContractExt.usrOnBudget> e) 
  2. In CalculateCompletedPerc your las line of code is never going to be executed as you are returning anyways before that point.

Also I suggest

  1. move your decimal percentage = (actualCostQty / actualRevenueAmount) * 100; into the if so you won’t get error in case you have actualRevenueAmount zero.
  2. assign either zero or your calculated formula to a variable and return at the end of your method
  3. Use Base.Projects.Update(contract) as you already have it initiated in the Base.
  4. Instead of using LINQ you can use GroupBy <AggregateTo<Sum<YourField>>> and tally your project revenue and cost.

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings