pmfith
pmfith

Reputation: 909

Can I alias a field in a PXSelector

I have a selector defined as follows:

[PXSelector(typeof(Search2<xTACTaxDocument.iD, 
                              InnerJoin<xTACEntityMappingEIN, 
                                  On<xTACTaxDocument.clientEINID, Equal<xTACEntityMappingEIN.iD>>,
                              InnerJoin<xTACEntityMappingEIN1, 
                                  On<xTACTaxDocument.investmentEINID, Equal<xTACEntityMappingEIN1.iD>>>>>),
                typeof(xTACTaxDocument.iD),
                typeof(xTACTaxDocument.formID),
                typeof(xTACTaxDocument.year),
                typeof(xTACEntityMappingEIN.eIN),
                typeof(xTACEntityMappingEIN1.eIN))]

Where I define an alias DAC as follows(redefining the fields I need to use) :

[Serializable]
public class xTACEntityMappingEIN1 : xTACEntityMappingEIN
{
    public abstract new class iD : IBqlField { }
    public abstract new class eIN : IBqlField { }
}

My question is - since the original ein and aliased DAC ein fields have the same name - is it possible - purely in the displayed grid - to rename the second one? Or, ideally, rename both of them? Didn't see that as an option anywhere in the intellisense...

This is kind of what I'm looking to do (see the aliased fields):

select  xTACTaxDocument.iD
       ,xTACTaxDocument.FormID
       ,xTACTaxDocument.Year
       ,xTACEntityMappingEIN.EIN as 'ClientEIN'
       ,xTACEntityMappingEIN1.EIN as 'InvestmentEIN'
from    xTACTaxDocument
        Inner Join  xTACEntityMappingEIN
            On xTACTaxDocument.clientEINID = xTACEntityMappingEIN.iD
        Inner Join  xTACEntityMappingEIN xTACEntityMappingEIN1
            On xTACTaxDocument.investmentEINID = xTACEntityMappingEIN1.iD

Upvotes: 0

Views: 322

Answers (2)

Brendan
Brendan

Reputation: 5613

The DAC Names need to be unique to "alias" a table. You cannot set an alias like you might use in SQL, but you can declare a new class inheriting the source class to give it a new "name" for the query. I had a similar Q&A here: Acumatica BQL Query with the same table more than once

In the inherited class you can change the display name of the fields as needed to "alias" a field name that repeats.

Here is a quick untested sample:

[Serializable]
public class xTACEntityMappingEINClient : xTACEntityMappingEIN
{
    //Override field to set display name = "ClientEIN"
    //[PXUIField(DisplayName = "ClientEIN")]
}

[Serializable]
public class xTACEntityMappingEINInvestment : xTACEntityMappingEIN
{
    //Override field to set display name = "InvestmentEIN"
    //[PXUIField(DisplayName = "InvestmentEIN")]
}

[PXSelector(typeof(Search2<xTACTaxDocument.iD,
    InnerJoin<xTACEntityMappingEINClient,
        On<xTACTaxDocument.clientEINID, Equal<xTACEntityMappingEINClient.iD>>,
    InnerJoin<xTACEntityMappingEINInvestment , 
        On<xTACTaxDocument.investmentEINID, Equal<xTACEntityMappingEINInvestment.iD>>>>>),
                typeof(xTACTaxDocument.iD),
                typeof(xTACTaxDocument.formID),
                typeof(xTACTaxDocument.year),
                typeof(xTACEntityMappingEINClient.eIN),
                typeof(xTACEntityMappingEINInvestment .eIN))]

Upvotes: 0

RuslanDev
RuslanDev

Reputation: 6778

The only option would be to additionally override the EIN property in the xTACEntityMappingEIN1 DAC to use a different DisplayName in PXUIFieldAttribute:

[Serializable]
public class xTACEntityMappingEIN1 : xTACEntityMappingEIN
{
    public abstract new class iD : IBqlField { }
    public abstract new class eIN : IBqlField { }

    [PXDBString(50, IsUnicode = true, IsKey = true)]
    [PXUIField(DisplayName = "Investment EIN")]
    public override string EIN { get; set; }
}

Please note, in the code snippet above I randomly chose string type for the EIN field. Ideally EIN field attributes should be close to identical in both xTACEntityMappingEIN and xTACEntityMappingEIN1, except the DisplayName property value for PXUIFieldAttribute.

Upvotes: 1

Related Questions