complete assign next agent

added validation to check if reached the last record of the database