Question Status

Verified
Santosh Artham asked a question on 11 Jan 2013 2:35 PM

Hi, I have a requirement to create a SalesLine record next to the selected record in SalesTable form on button click. How do i get a new record next to current record - is there is out of box function that generates appropriate LineNumber ?

Thanks in Advance,
San


Reply
Verified Answer
Martin Dráb responded on 14 Jan 2013 4:27 AM

AX assigns LineNum only if you don't provide any - so just fill it before calling createLine(). The usual value is half of the interval between the current line num and the next one (the distance doesn't have to be 1.00).

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply
Suggested Answer
Joris de Gruyter responded on 11 Jan 2013 3:21 PM

I wouldn't advise you to insert the record into salesline manually. However, the salesline table has a special method called "createLine" which handlers a bunch of funtionality that you would otherwise miss when doing the insert manually.

Among other things, it will take care of the line number for you. Just fill in the fields in the SalesLine buffer you have (call initFromXXX() where available and potentially modifiedField() as well for the fields you are filling in). Then instead of insert(), call createLine().

Use this API as it will also give you potential future functionality for free.

Reply
Suggested Answer
Joris de Gruyter responded on 14 Jan 2013 9:13 AM

I agree the line numbers are very loose in AX. Even worse, it's not even enforced to be unique on the database level. I've noticed at clients that have been live for quite a while that typically duplicate numbers for lines start showing up. So on the flip side of this, be careful using the line number for any reporting other than just displaying it :-)

Reply
Suggested Answer
Joris de Gruyter responded on 11 Jan 2013 3:21 PM

I wouldn't advise you to insert the record into salesline manually. However, the salesline table has a special method called "createLine" which handlers a bunch of funtionality that you would otherwise miss when doing the insert manually.

Among other things, it will take care of the line number for you. Just fill in the fields in the SalesLine buffer you have (call initFromXXX() where available and potentially modifiedField() as well for the fields you are filling in). Then instead of insert(), call createLine().

Use this API as it will also give you potential future functionality for free.

Reply
Santosh Artham responded on 12 Jan 2013 8:22 AM

yep, i am using the same approach but in this way the line number that is generated is reflecting the (LineNumber +1) for the current SalesOrder. But my requirement is that it should be next to selected line , just like how natively it works when user creates a line in SalesTable form.


Reply
Dominic Lee responded on 14 Jan 2013 1:26 AM

AX itself is pretty loose about how to assign the line number. I think modification is needed for your specific needs.

kind regards,

Dominic Lee

My blog | PBC

This forum post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

Reply
Verified Answer
Martin Dráb responded on 14 Jan 2013 4:27 AM

AX assigns LineNum only if you don't provide any - so just fill it before calling createLine(). The usual value is half of the interval between the current line num and the next one (the distance doesn't have to be 1.00).

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply
Santosh Artham responded on 14 Jan 2013 8:53 AM

thanks Martin and Dolee for confirming that this is not available out of box. I will work on getting this logic in X++.

Thanks again,

San


Reply
Suggested Answer
Joris de Gruyter responded on 14 Jan 2013 9:13 AM

I agree the line numbers are very loose in AX. Even worse, it's not even enforced to be unique on the database level. I've noticed at clients that have been live for quite a while that typically duplicate numbers for lines start showing up. So on the flip side of this, be careful using the line number for any reporting other than just displaying it :-)

Reply
Dave71 responded on 19 Feb 2013 6:21 AM

Hi, I have an issue with line numbers on sales orders that i hope you can help me with.  

We use the process industries version of AX, and if from a sales line i use the Function / Explode formula function, the original sales line is cancelled and lines are created for its formula lines as follows

Line 1.00000000

after using the explode formula function i get

Line 1.00000000  is cancelled

Line 1.00000001 is created

Line 1.00000002 is created

All this is fine except if you then add another item to the order, the sales line number is calculated as 2.00000002 which is causing me a problem as i need all lines that have not been exploded to be integers so that i can trace back the original sales item.

any ideas?

Reply
Martin Dráb responded on 19 Feb 2013 6:37 AM

It won't ever work as you expect unless you change the default behavior - for example, if you insert a line between line 1 and 2, it will get line num 1.5, which is obviously not an integer.

You can adjust the way how line num is assigned in SalesLine.createLine() (= last line num

+ 1), but you still have to cope with the previous point.

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply
Dave71 responded on 19 Feb 2013 8:29 AM

Thanks for your response Martin.  I will look to change the class to move it to the next integer rather than just adding 1.0 as this should solve our issues.

Reply