web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

AOT map

(2) ShareShare
ReportReport
Posted on by 1,965
Hi,

I have a scenario, where sometimes i need to read values from "salesLine" and sometimes from "salesQuotatioLine" based on caller. And what i want to do is take some of the values from one of those tables and send them out of F&O by calling an external api

As you know the fields in both tables "salesLine" and "salesQuotatioLine" are almost the same and i also created custom fields that exist in both tables. So i don't want to end up doing this in "initXContract" method:
    public void initFromArgs(Args _args)
    {
        if(_args.record())
        {
            if(_args.record().TableId == tableNum(SalesQuotationLine))
            {
                quotationLine   = _args.record();
            }
            else if(_args.record().TableId == tableNum(salesLine))
            {
                salesLine   = _args.record();
            }
            else
            {
                throw error(Error::wrongUseOfFunction(funcName()));
            }
        }
        
    }

public void run()
{
    if(quotationLine)
    {
        XContract xContract = this.initXContract(quotationLine);
        if(quotationLine.Field1)
        {
            Class1::send(quotationLine, xContract.parmField1());
        }
        else
        {
            class2::send(quotationLine,xContract.parmField1());
        }
    }
    else if(salesLine)
    {
        XContract xContract = this.initXContract(null, salesLine);
        if(salesLine.Field1)
        {
            Class1::send(salesLine, xContract.parmField1());
        }
        else
        {
            Class2::send(salesLine, xContract.parmField1());
        }
    }
   
}

public XContract initXContract(SalesQuotationLine _salesQuotationLine, SalesLine _salesLine = null)
{
    XContract xContract = new XContract();
    if(_salesQuotationLine && !_salesLine)
    {
        xContract.parmField1(_salesQuotationLine.Field1);
        xContract.parmField2(_salesQuotationLine.Field2);
        xContract.parmField3(_salesQuotationLine.Field3);
    }
    else if (_salesLine && !_salesQuotationLine)
    {
        xContract.parmField1(_salesLine.Field1);
        xContract.parmField2(_salesLine.Field2);
        xContract.parmField3(_salesLine.Field3);
    }

    return xContract;
}

So the question is

1. Would it better to extend the existing standard map "SalesPurchLine" or create a new one? How to decide?
2. If i extend the existing standard map to add more custom fields that are common between salesQuotationLine and SalesLine, how would it affect the standard map and the places it's called?
3. is it correct in general to add fields to SalesPurchLine, while the fields don't exist in purchLine?
but if i go the salesQuotationTable, i can see this map anyways


How to decide which way is better and the impact it will make?

4. or based on the business scenario i mentioned, is it better to do separate classes for example?
Categories:
I have the same question (0)
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,390 Super User 2025 Season 2 on at
    Hi @..,
     
    In my opinion, you should use the common buffer instead of putting two tables in the parameters of the initXContract method.
    e.g.
    public XContract initXContract(Common _common)
    {
       //Your logic here
    }
    Best regards,
    Mohamed Amine MAHMOUDI
  • .. Profile Picture
    1,965 on at
    Hi Mohammed,

    My idea is not about passing common or tables. 

    my idea is that both of those tables have common fields, so using common would still require me to do if and else and repeat filling the fields for each one. that's why i asked about the map
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,390 Super User 2025 Season 2 on at
    Hi @..,
     
    I understand, but you can't extend Maps.
    However, you can duplicate them and add custom fields if you want o use Maps.
     
    BR,
     
  • .. Profile Picture
    1,965 on at
  • Suggested answer
    Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    The article claims that you can extend maps, but it actually says that some maps have been replaced by a class hierarchy that, unlike maps, can be extended. Creating a map for your specific scenario (rather then extending SalesPurchTableInterface) is a better design, in my opinion. You can give the map a name describing its purpose, you can implement it for the tables you need (SalesPurchLine covers several other tables) and it'll be much less work.
  • .. Profile Picture
    1,965 on at
    Hi Martin,

    I was able to extend SalesPurchLine map using the interface. I agree that creating a new one is easier
     
    but i would like to know why you thought creating a new one in my scenario is better? is it because i'm only using it to extract values?

    and if you can please also answer those two questions i mentioned in the post
     
    2. If i extend the existing standard map to add more custom fields that are common between salesQuotationLine and SalesLine, how would it affect the standard map and the places it's called?
     
    3. is it correct in general to add fields to SalesPurchLine, while the fields don't exist in purchLine?
    but if i go the salesQuotationTable, i can see this map anyways
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    In general, you should give all elements names that describe the purpose of the given EDT, class and so on. This apply to maps as well. So if you want to create a map for a specific purpose, the name should refelect the name. This isn't met if you just throw the fields to SalesPurchLine map.
     
    Also, the name SalesPurchLine says the purpose is to share functionality common to sales order lines and purchase order lines. But your requirement has nothing to do with purchase orders.
     
    Another problem is that only 10% of table mapping to SalesPurchLine would support your fields. Any attempt to use them on the remaining 90% would fail. Not mapping some fields on all tables is possible, but if almost no mapped table uses them, it's an indidication that the map isn't used correctly.
     
    Regarding your questions:
    2. As already discused, maps can't be extended. You can extend the classes that replace some of the maps. Is there something in particular what you want to learn about class extensions?
    3. Already covered above.
  • .. Profile Picture
    1,965 on at
    Hi @Martin Dráb,

    Regarding this sentence "Also, the name SalesPurchLine says the purpose is to share functionality common to sales order lines and purchase order lines. But your requirement has nothing to do with purchase orders.
    Then why SalesQuotationLine table has "SalesPurchLine" in it's mappings node?
     
     
    Also I didn't understand this, can you please explain further what do you mean by 10% is supported while others would fail?
    "Another problem is that only 10% of table mapping to SalesPurchLine would support your fields. Any attempt to use them on the remaining 90% would fail. Not mapping some fields on all tables is possible, but if almost no mapped table uses them, it's an indidication that the map isn't used correctly."
     
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    Question: Then why SalesQuotationLine table has "SalesPurchLine" in it's mappings node?
    Answer: It's a part of a solution where several (twenty) tables use some common logic related to purchase and sales lines. That's a different case then yours where you have no intention to share any logic with any purchase tables.
     
    Request: please explain further what do you mean by 10% is supported while others would fail?
    If anyone tries to use a logic of a map, such as accessing a field, with a table doesn't provide mapping to that field, it must fail. For example, you add Field1 to SalesLine and SalesPurchLine map and have some code working with SalesPurchLine.Field1. When someone calls it with PurchLine, the system will try to find a corresponding field on PurchLine, but it'll fail, because no such a field exists. The map is used by twenty tables but you support just two, which is 10%
  • .. Profile Picture
    1,965 on at
    Hi @Martin Dráb,

    but the 20 tables would use salesPurchLine directly or  SalesPurchLineInterface salesPurchLineInterface = salesPurchLine.salesPurchLineInterface();

    but in order to see field1, they would need to do call the customized class explicitly
    PrefixSalesPurchLineInterface prefixSalesPurchLineInterface = salesPurchLineInterface.PrefixSalesPurchLineInterface();
    prefixSalesPurchLineInterface.parmField1();

    I mean wouldn't the one calling this class only call it if they are interested in fields inside this extension?
    and if they did, would it really fail? because at the end it's a parm method and not actually a field
    I mean if field1 doesn't exist in purchLine, how would someone try to call it with PurchLine?
    they can't call it using SalesPurchLine map directly
    they will need to call the extension class
    and even if they did, it won't fail i think, if we assume Field1 is string and i put
    purchLine.AndStringField = prefixSalesPurchLineInterface.parmField1();  it won't fail right?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans