Only add where clause based on elementId, if it is not null.

Something was going wrong when adding a new entry, so that it was returning a false positive for the validation because the elementId being checked was blank.