If you are working with a List Grid that uses some type of sequence field (e.g. SEQNO, LINE_SEQ, SORT_SEQ) , there is a handy bit of technology that you can use that will cause the UI to do this job for you.
Just follow the steps below and you'll have the problem solved in no time. The sequence field will be populated in your "empty line" and any elements that are added from then on will have an appropriate value in the sequence field. If the user edits the sequence field at any point, the next element added to the list will incorporate the change without any problems.
function initializeNewElement_LIST_NAME(newElement) {
var myListName = "LIST_NAME";
var myListSeqName = "FIELD_NAME";
var myListMaxSeq = 999;
defaultSequenceNumber(myListName,myListSeqName,myListMaxSeq,newElement)
}
</SCRIPT>
<SCRIPT src="/zz/defaultSequenceNumber/defaultSequenceNumber.js"></SCRIPT>
<SCRIPT>