Skip to main content

Hello everyone,

In the below popup(Bank deposit->Add payment), I have added a custom button(Update).

In the button click, I will verify some conditions and I have to update the selected checkbox to true to the payments which are satisfied the conditions. 

But, I’m unable to update the checkbox to true. Below is the code i have tried.

 #region Event Handlers
public PXAction<PaymentInfo> ImportPayment;

PXButton()]
PXUIField(DisplayName = "Update")]
public virtual IEnumerable importPayment(PXAdapter adapter)
{
if (Base.AvailablePayments.Any())
{
foreach (PaymentInfo paymentInfo1 in Base.AvailablePayments.Select())
{
if (paymentInfo1.ExtRefNbr == "417028599")//Some conditions need to be checked to make selected checkbox true
{
paymentInfo1.Selected = true;
// Base.AvailablePayments.Cache.Update(paymentInfo1);

//Base.Cachesctypeof(PaymentInfo)].SetValueExt<PaymentInfo.selected>(paymentInfo, true);


}
}
}
return adapter.Get();
}


#endregion

 

How do i make few payments checkbox to be true automatically when user clicks on update button?

Can anyone suggest what is the issue here.

Attached the complete design and package here.

 

Thanks in advance.

 

Hi @ssamboju12 

 

I see you are working with the Bank Deposits screen.  The Primary DAC for the base PXGraph for this screen is CADeposit.

 

Try changing the PXAction line from

public PXAction<PaymentInfo> ImportPayment;

to

public PXAction<CADeposit> ImportPayment;

Even though your Action only interacts with the AvailablePayments dataview, and even though you have placed your Action button on the grid section of the ‘Add Deposit to Payment’ panel, your Actions still need to be based on the CADeposit DAC.


Hello @stephenbologna39 

Thanks for the response.

I have tried with both DACs in the PXAction. Still, I’m not able to update the check box.

Do you think any other logic to be added in the action?

Thanks,

 


Is there a reason your action declaration is not set to commit changes?

[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Update")]
public virtual IEnumerable importPayment(PXAdapter adapter)

Not positive this will help, but I think it’s pretty important.

Also pretty sure you’ll need the line to update the cache no matter which way you do it:

Base.AvailablePayments.Cache.Update(paymentInfo1);

For what it’s worth, I’m a big fan of this method:

Base.AvailablePayments.SetValueExt<PaymentInfo.selected>(paymentInfo1, true);
Base.AvailablePayments.Update(paymentInfo1);

 


Hello @Deetz ,

Thank you for your response.

Yes, I have tried with commit changes = true at the action level and at aspx level as well but it didn’t worked for me.

I have updated the view caches after assigning the checkbox to true, but this is also not worked.

 

I tried with setvalue and setvalueext to assign the true to checkbox, but still same issue.

 


Have you verified the code is executing?

 

If nothing else, writing to the trace log can be a useful way to test this:

PXTrace.WriteInformation("!");

 

If the code is executing, I won't be able to help further I'm afraid, but I would confirm that.


Hello everyone,

How do i make few payments checkbox to be true automatically when user clicks on update button?
 

 

The reason why checkbox does not get selected is because of the way how AvailablePayments view is implemented.  Its view delegate is always returning new records is the main reason. Overriding the view delegate and re-implementing base logic can get this working.  Example below:

    public class CADepositEntry_Extension : PXGraphExtension<CADepositEntry>
    {
        #region Event Handlers

        public delegate IEnumerable availablePaymentsDelegate();
        ePXOverride]
        public IEnumerable availablePayments(availablePaymentsDelegate baseDelegate)
        {
            foreach (PaymentInfo row in baseDelegate())  // base code always creates new rows
            {
                // so we need to check in the cache has it already
                // and return the row with selection of that cached row
                var foundRow = (PaymentInfo)Base.AvailablePayments.Cache.Locate(row);
                row.Selected = foundRow?.Selected;
                yield return row;
            }
        }

        public PXAction<PX.Objects.CA.CADeposit> Test;

        yPXButton(CommitChanges = true)]
        }PXUIField(DisplayName = "Test")]
        protected void test()
        {
            var cache = Base.CachesÂtypeof(PaymentInfo)];
            foreach (PaymentInfo row in Base.AvailablePayments.Select())
            {
                row.Selected = true;  // you can select conditionally
                Base.AvailablePayments.Cache.Update(row);
            }
        }

        #endregion
    }

 


Reply