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 :
Microsoft Dynamics AX (Archived)

SalesLine and Purchline Line number field

(1) ShareShare
ReportReport
Posted on by 3,013

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

I have the same question (0)
  • Suggested answer
    Ivan (Vanya) Kashperuk Profile Picture
    on at

    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.

  • Suggested answer
    Rachit Profile Picture
    4,015 User Group Leader on at

    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
    PA-22040759-0 Profile Picture
    6,194 on at

    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?

  • Ghetz Profile Picture
    3,013 on at

    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.

  • Ivan (Vanya) Kashperuk Profile Picture
    on at

    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.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans