Set task index before save