In the line of duty

Done as part of a job.

The police officer was killed in the line of duty during a bank robbery.