AlexS
AlexS

Reputation: 53

Acumatica : Is my joined selector badly written?

I'm just starting coding in Acumatica and I'm trying to add Sectors to the customer screen. I created a SQL Sector table (TRSector) with the 18 different sectors' names and codes. I also created another SQL table (TRCustSectorActive) that has all the combinations of customers' accounts and sector codes with additional information (is it active or not, dates, etc). The idea is that each customer will have information about each sector.

I'm trying to add a selector for the sectors on the customer page (AR303000). The problem I'm facing is that even though my selector is showing correctly if I try to change the sector, my selection automatically comes back to the first line. I'm guessing I'm doing something wrong when joining my two tables? Or should I have a CurrentSector view in my graph ?

Here are more details about my code. The selector in my TRCustSectorActive DAC looks like this :

#region SectorCD
[PXDBString(20, IsKey = true, IsFixed = true, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Filière")]
[PXSelector(
  typeof(Search2<TRCustSectorActive.sectorCD, LeftJoin<TRSector, On<TRCustSectorActive.sectorCD, Equal<TRSector.sectorCD>>>, Where<TRCustSectorActive.bAccountID, Equal<Current<Customer.bAccountID>>>>),
  typeof(TRCustSectorActive.sectorCD),
  typeof(TRSector.name),
  typeof(TRCustSectorActive.active)
)]
public virtual string SectorCD { get; set; }
public abstract class sectorCD : IBqlField { }
#endregion

I joined the TRSector DAC so that I can show the names of the sectors in the selection.

The view in the CustomerMaint extension looks like this :

public PXSelect<TRCustSectorActive, Where<TRCustSectorActive.bAccountID, Equal<Current<Customer.bAccountID>>>> Sector;

And in the page, I added this bit :

<px:PXFormView ID="DefFiliere" runat="server" Caption="Activation Filières" DataMember="Sector" RenderStyle="Fieldset" DataSourceID="ds" TabIndex="2100">
    <Template>
       <px:PXLayoutRule runat="server" ControlSize="SM" LabelsWidth="SM" StartColumn="True" />
       <px:PXSelector runat="server" ID="edSector" DataField="SectorCD"/>
       <px:PXLayoutRule runat="server" StartColumn="True" LabelsWidth="SM" ControlSize="SM" />
       <px:PXCheckBox runat="server" ID="edActive" DataField="Active"/>
    </Template>
</px:PXFormView>

Upvotes: 2

Views: 393

Answers (2)

Evgeny Kralko
Evgeny Kralko

Reputation: 342

  1. Your selector is ok
  2. The problem is in your view declaration.

This view returns several records for the current Customer. As a result, Search method will take only the first line.

Customer1 Sector1
Customer1 Sector2
Customer1 Sector3
...

Further, depending on what you need there are several possible options to fix the issue:

  1. Use the grid to show all available sectors for the current Customer (see "Locations" or "Payment Methods" tab as an example) enter image description here

  2. Add a new filter (SectorFilter for example) to show Sector data only for the selected sector

see code below

public PXFilter<SectorFilter> sectorFilter;

[Serializable]
public partial class SectorFilter : IBqlTable
{
    #region SectorCD
    public abstract class sectorCD : IBqlField { }

    [PXDBString(20, IsFixed = true, IsUnicode = true, InputMask = "")]
    [PXUIField(DisplayName = "Filière")]
    [PXSelector(
        typeof(Search2<TRCustSectorActive.sectorCD, LeftJoin<TRSector, On<TRCustSectorActive.sectorCD, Equal<TRSector.sectorCD>>>, Where<TRCustSectorActive.bAccountID, Equal<Current<Customer.bAccountID>>>>),
        typeof(TRCustSectorActive.sectorCD),
        typeof(TRSector.name),
        typeof(TRCustSectorActive.active)
    )]
    public virtual string SectorCD { get; set; }
    #endregion
}

public PXSelect<TRCustSectorActive, 
    Where<TRCustSectorActive.bAccountID, Equal<Current<Customer.bAccountID>>, 
        And<TRCustSectorActive.sectorCD, Equal<Current<SectorFilter.sectorCD>>>>> Sector;

and aspx

<px:PXFormView ID="formSectorFilter" runat="server" DataSourceID="ds" Style="z-index: 100" Width="100%" CaptionVisible="False"
    DataMember="sectorFilter" SkinID="Transparent">
    <Template>
        <px:PXLayoutRule runat="server" StartColumn="True" LabelsWidth="S" ControlSize="XM" />
        <px:PXSelector CommitChanges="True" ID="edSectorCD" runat="server" DataField="SectorCD" AutoRefresh="True"/>
    </Template>
</px:PXFormView>

<px:PXFormView ID="DefFiliere" runat="server" Caption="Activation Filières" DataMember="Sector" RenderStyle="Fieldset" DataSourceID="ds" TabIndex="2100">
<Template>
   <px:PXLayoutRule runat="server" ControlSize="SM" LabelsWidth="SM" StartColumn="True" />
   <px:PXLayoutRule runat="server" StartColumn="True" LabelsWidth="SM" ControlSize="SM" />
   <px:PXCheckBox runat="server" ID="edActive" DataField="Active"/>
</Template>

Upvotes: 1

Joseph Caruana
Joseph Caruana

Reputation: 2271

Could you please include your entire property definition (not just the selector attribute)? Make sure that you have defined your field correctly, including the BqlField class definition.

Also, to start troubleshooting your issue, I would start with a simpler selector such as the below, so that you can eliminate whether it is related to the join or not.

[PXSelector(
    typeof(TRCustSectorActive.sectorCD),
    typeof(TRCustSectorActive.sectorCD),
    typeof(TRSector.name),
    typeof(TRCustSectorActive.active)
)]

Upvotes: 0

Related Questions