Get the highest number or the next available number in a list

Cleaven

I'm encountering a problem with assigning the next invoice line value.

I have written a piece of javascript to get the next value but somehow it is missing the next available value and still choosing the highest value.

What I need is the highest or the next available number, LineNo is what I need the highest or next of.

Code

onGridBeforeEditLines: function (e) {//grid 2
    var event123 = e;
    var lineNo = 0;
    var grid = $("#gridLines").data("kendoGrid");
    $(grid.dataSource.data()).each(function (i, v) {
        if (v != null) {
            if (v.LineNo >= lineNo)
                lineNo = v.LineNo; //Getting the highest value    
        }
    });
    lineNo++;
    grid = $("#gridContracts").data("kendoGrid");
    if (e.model.PaymentPeriodID == 0) {           
        var selectedItem = grid.dataItem(grid.select());
        e.model.PaymentPeriodID = selectedItem.ID;
        e.model.LineNo = lineNo; //setting the value to the grid
    }        
},

Images

It seems to work fine for getting the highest number and adding 1 to it. The highest is 3, so 4 is the next available line number. Correct

It doesn't seem to work in when finding the next available number. I have removed line no 2 so 2 should be the next available option but it still gets the highest and adds 1 to it. Incorrect

Thank you in advance for help.

KevinB
if (v.LineNo > lineNo+1) { // then we skipped a space
  // next open value is lineNo+1
  lineNo = lineNo+1;
  return false; // break loop
} else if (v.LineNo == lineNo+1) {
  lineNo = v.LineNo; //Getting the next sequential value , keep looping
} else {
  // lineNo should stay the same
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do i get the highest available number in a substring of a list item

If number is not in list return next highest number + python

Swift: Get next highest number that ends in zero

get highest number then print next number in new file

Find the next available number in a python list

compare available list print number in next line

Highest number in list and append

Get the highest number of the array

Get minimum available number in list of integers

How do I sequentially get the index and column of the highest, next highest, etc. number in a pandas dataframe?

From a list of dicts, get a number N of dicts with highest values

How to get list([a,2],[a,1],[a,3]) with the highest number([a,3])

Displaying the Next Available Number in a sequence

Next available number for multiple cases

Sorting highest number in a linked list

Picking the highest number in a list of strings

Get the number of highest ID number column

Get highest score and number of wins

How to get the highest and lowest number

Round number to next highest greatest place

Get second maximum number only if highest one not available in SQL and not return null value

Is there a way to find the number with the highest probability of being the next one in a user input list?

divide a number from the available list

How to find out next available number

1 liner RegEx to find next available number

replacing NA with next available number within a group

How to find all occurences of the highest number in a list?

Extracting a given number of the highest values in a List

sort a defaultdict(list) by highest item number