Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to create LineNum field automatically!

917 views
Skip to first unread message

NamTruong

unread,
Oct 6, 2009, 4:11:03 AM10/6/09
to
Dear @all,
I create new Form; and I have one field LineNum (It's the same LineNum field
on Sales Order Details form). But I don't know that how to create LineNum
field increasing automatically (1,2,3...) when I create new line on form.

Please, give me simple example with this case.

Thanks and Best regards
--
AX Technical Consultant

sudhir

unread,
Oct 6, 2009, 6:40:02 AM10/6/09
to
Hi,
You have to override the insert() method on that table to set column number.
Below is the example for that
void insert()
{
MyTable MyTable;
;
if (this.Column == 0)
{
select maxof(Column) from MyTable
where MyTalble.JournalID == this.JournalID

this.Column = MyTable.Column + 1;
}

super();
}

Thanks
Sudhir
http://www.sudhirpaliwal.blogspot.com/

TSA

unread,
Oct 6, 2009, 7:06:01 AM10/6/09
to
Hi There

If you are creating the records in a form (like SalesTable) you can specify
the LineNum as CounterField on the DataSource.

NamTruong

unread,
Oct 6, 2009, 10:15:01 AM10/6/09
to
Dear TSA,
Thanks for your reply. But I used to try with your answer. But It not working.

You can see with my sreen shoot follow this link (I don't know how to give
attachment file via this forum):

http://www.dayza.com/Users-Photos/1254838326.gif
http://www.dayza.com/Users-Photos/1254838382.gif

Best regards
--
AX Technical Consultant

Home page: http://erp4vn.net

TSA

unread,
Oct 7, 2009, 2:40:01 AM10/7/09
to
Hi Again

I can think of two things:

#1
First of all you data sources seems to be in the "wrong" order, meaning that
the "line" DS is #1. I dont know whether this is the reason, but I have seen
strage things happen on forms when the DS's are created in the "wrong" order.

#2
Is your LineNumber field of the correct type? It needs to be a 'real'
DataType and not an integer. Extending or using the existing LineNum DataType
might do the trick.

Jack

unread,
Oct 7, 2009, 6:15:01 AM10/7/09
to
As one of the options you can owerride initValue method on the table.
It will populate LineNum field when new record is initiated.
Here is sample code:

BaseMachineLine BaseMachineLine;
;
select maxOf(LineNum)
from BaseMachineLine
where BaseMachineLine.OrderId = this.OrderId; // optional link to the parent
table

this.LineNum = BaseMachineLine.LineNum + 1;


Placing similar code in insert() (as suggested in one of the answers)
probably is not a good idea because this field likely to be mandatory, so
validateWrite on the table will fail if record is created on the form.

Regards,
Jack

Axel Kühn

unread,
Oct 7, 2009, 3:02:02 PM10/7/09
to
Hi,

as Jack sayed earlier...
...overwrite the initValue method on your table.

But you should also override the insert method (and update method) and check
if the LineNum field has a valid value (Could be possible that a user changes
the LinNum field after initalisation).

To not write the same code many times, just place the code to get a new
LineNum (i.e. the code Jack has posted) in a new separate method.

Example:
public LineNum LineNumNext()
{
YourTable buffer;
;
select maxof(LineNum) from buffer
where buffer.ID == this.ID

return buffer.LineNum + 1;
}

In the initValue you have to write something like this:

this.Id = SomeValue;
this.LineNum = this.LineNumNext();

But you have to make sure that your record has the ID Field field befor you
are calling "LineNumNext".

Hope this helps you.
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)

NamTruong

unread,
Oct 8, 2009, 12:24:03 AM10/8/09
to
At first, I want to say thanks to you (Subhir, TSA, Jack and Axel Kühn). It's
working with your guide. But I have a little on Grid when add new line. It's
not add new line on below the last row; it pushed present row on below and
appear on the top this row.

You can see my problem clearly with these link attachment:
http://www.dayza.com/Users-Photos/1254975601.gif
http://www.dayza.com/Users-Photos/1254975631.gif
http://www.dayza.com/Users-Photos/1254975660.gif
http://www.dayza.com/Users-Photos/1254975689.gif

Do you have any ideas for my problem?


--
AX Technical Consultant
Home page: http://erp4vn.net

0 new messages