0

First of all, sorry for my English !!!

I need to customize the grid (DunningLetterList) in the screen AR521000.

In this grid, we have the BAccountid. In the database, each BAccountId (customer) has one (and only one) salesperson checked by default (checkbox "Default" in the "Salespersons" tab in the CustomerMaint).

I need to add the name of this default salesperson in the DunningLetterList, for each customer that appears on the list.

Is it possible, knowing that it's a process screen ? And if it's possible, how can I do that ?

Thanks in advance !!

AmélieG
  • 25
  • 4

2 Answers2

1

I am afraid there is no easy solution without affecting performance. That's because the rows from grid are not inserted in cache as usual, but generated inside the data view delegate and added with cache.Hold(row);

Therefore the only solution that I found is to add the sales person's name on RowSelected. (!) Beware this is not recommended by Acumatica customization best practices (although you might find this kind of selects here and there). Just to let you know, the SQL generated query is SELECT TOP (1).

The customization of business logic:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using PX.Data;
using PX.Objects.CM;
using PX.Objects.CS;
using PX.Objects.GL;
using PX.SM;
using static PX.Objects.Common.Extensions.CollectionExtensions;
using PX.Objects;
using PX.Objects.AR;
using ARDunningLetterList = PX.Objects.AR.ARDunningLetterProcess.ARDunningLetterList;

namespace PX.Objects.AR
{

public class ARDunningLetterListSP : PXCacheExtension<ARDunningLetterList>
{
    #region SalesPerson
    public abstract class salesPerson : PX.Data.BQL.BqlString.Field<salesPerson> { }
    [PXString(60)]
    [PXUIField(DisplayName = "Sales Person")]
    public virtual string SalesPerson { get; set; }
    #endregion

 }

public class ARDunningLetterProcess_Extension : PXGraphExtension<ARDunningLetterProcess>
{
   public virtual void ARDunningLetterList_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
    {
      ARDunningLetterList row = e.Row as ARDunningLetterList ;
        if (row == null) return;

     SalesPerson sp = PXSelectJoin<SalesPerson,
               InnerJoin<CustSalesPeople, On<SalesPerson.salesPersonID, Equal<CustSalesPeople.salesPersonID>>>,
                  Where<CustSalesPeople.bAccountID, Equal<Required<CustSalesPeople.bAccountID>>, And<CustSalesPeople.isDefault, Equal<True>>>>.SelectSingleBound(this.Base, null, row.BAccountID);

      var rowExt = row.GetExtension<ARDunningLetterListSP>();
       rowExt.SalesPerson = sp?.Descr;

    }
}
}

Then you add the custom field in the grid.

Note: I've tried other solutions as well (like overriding the data view (adding joined tables), the delegate, or using attributes to calculate the value, but I had no luck).

Lucian
  • 309
  • 2
  • 8
0

I knew it wouldn't be easy !! Thank you for your answer and your researches !!

It works perfectly !!

Do you know why I can't filter or sort this column ? I added the "AllowFilter" and "AllowSort" properties, but it doesn't work.

AmélieG
  • 25
  • 4
  • Please don't forget to mark it as answer, if it does meet your needs. I guess the filter is not working because the value is written when the row is selected, so there is nothing inside when you apply the filter. – Lucian Dec 22 '20 at 22:31