function getNextID(number,callback){
var maxKey = 0;
number = typeof number !== 'undefined' ? number : 1;
db.from('contributions').select('id').list().done(function(records) {
records.forEach(function(item){
if (maxKey < item){
maxKey = item;
}
});
callback(maxKey);
});
}
then in your code
getNextID(number,function(maxKey){
// continue the code here.
});
since your code is async you cant return anything from getNextID but a promise or use a continuation (a callback).