Skip to main content



No record found.

Microsoft Dynamics AX forum
Suggested answer

SalesLine and Purchline Line number field

Posted on by 2,979

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

  • 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,979 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  is not correctly implemented in CIL.

  • Suggested answer
    PA-22040759-0 Profile Picture
    PA-22040759-0 6,192 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,011 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.

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,663 Super User

Martin Dráb Profile Picture

Martin Dráb 224,741 Super User

nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans