Former soldier Daniel Khalife was “devastated” to be told his Iranian heritage could prevent him from working in army intelligence, his trial has heard.