Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

SalesLine and Purchline Line number field

(1) ShareShare
ReportReport
Posted on by 2,983

Does anyone know the reason of this change in AX 2012?

In SalesLine the line number field is called LineNum with EDT LineNum of type Real.

In PurchLine, the line number field is called LineNumber with EDT TradeLineNumber and EDT Int64

Now I create a map for getting SalesLine and PurchLine mapped. I need the Line number mapped, but when I do CIL compile, I get "System.InvalidCastException" when passing a field from the map to a class method. I guess it's because the data types are different, but can't understand why this has been designed like this. Now

I cant work with a map for this 2 tables.

Trying to avoid this issue, I added this to my code, but still get "System.InvalidCastException" when running after CIL compile.

LineNum _linenumber;
_linenumber = any2real(this.LineNum); //"this" is my SalesLine/PurchLine Map
//any2real throws "System.InvalidCastException" under CIL

*This post is locked for comments

  • RE: SalesLine and Purchline Line number field

    CIL code simply has a lot more restrictions, as it is .NET framework behind it. X++ compiler and interpreter were simply always very lax in terms of various conversions which should not be valid. You can see the X++ team often posting another and another restriction on the compiler to make it closer to the .NET world.

  • Ghetz Profile Picture
    Ghetz 2,983 on at
    RE: SalesLine and Purchline Line number field

    The thing is we're upgrading a solution from AX 4 that uses a custom map, and makes calls to other classes, passing linenum as parameter. We wanted to avoid changing all class definitions and methods.

    For the moment we have created a new Int64 Tradelinenumber field in the map, and load a variable in code depending on the source table (purchline or salesline). We pass this variable to our classes that need a real (linenum) value. In this way any2real works.

    Anyway I think something must be checked on the kernel, as this works under X++ but fails under CIL.

    X++/MorphX will let you create a real field in a Map and get it mapped to a Int64 field. However, when running under CIL, this map will throw an exception when using this field in code and calling a method that takes a real value. Maybe the X++ autoconvertion explained here  https://msdn.microsoft.com/en-us/library/aa679079.aspx  is not correctly implemented in CIL.

  • Suggested answer
    PA-22040759-0 Profile Picture
    PA-22040759-0 6,194 on at
    RE: SalesLine and Purchline Line number field

    That was kind of an odd change in standard AX. The standard SalesPurchLine map won't really help you since they don't map PurchLine.LineNum anymore.

    any2Int64 also won't help you, as it will throw away the decimals.

    Maybe you can avoid to map the LineNum field, and just look it up when you need to know the value?

  • Suggested answer
    Rachit Profile Picture
    Rachit 4,015 User Group Leader on at
    RE: SalesLine and Purchline Line number field

    Hi Ghetz,

    In addition to Ivan comments, you can also refer to an already available map "SalesPurchLine" in standard AX which maps most of the fields from salesLine and purchLine table.

    Refer to \Data Dictionary\Maps\SalesPurchLine, this map also uses LineNum from both the tables.

    Hope this helps.

  • Suggested answer
    RE: SalesLine and Purchline Line number field

    you probably wanted to write any2int64 or something?

    I don't know for sure, I would assume it was done to simplify the line management part.

    It was pretty confusing before how the line numbers would be generated going deep into decimal values when you were creating a line not at the last position but at the middle.

    with integers it just gets much simpler.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans