sort by id to keep stuff in the same order
use the datatable workflow state preferentially