Refactor getRecord function
If there is no record selected or action is add create a new on