function getNextSequence(name,cb) {

    console.log("getNextSequence");
    var sql = 'SELECT \
            recid \
            FROM ' + name + ' \
            order by recid';

        w2db.exec(sql, function (err, result) {
            if (err) {
                console.log(err);
                res.send({
                    status  : 'error',
                    message : 'DB Error: '+ err
                });
                cb(-1);
            } else {
                // Last used recid should be in last record, but do this anyways
                var highest_recid=0;
                console.log("looking for records",result);
                var r;
                var len;
                for(var i=0, len=result.records.length; i < len; i++)
                {
                    console.log("f",result.records[i]);
                    r=result.records[i];
                    if (Number(r.RECID)>highest_recid) {
                        highest_recid=Number(r.RECID);
                    }
                }
                highest_recid=highest_recid+1;
                console.log("getNextSequence ",highest_recid,result);
                cb(highest_recid);
            }
        });
}
Module that helps to work with W2UI & db2

 DEPENDENCIES: underscore