In 1700, he obtained a jinshi position in the imperial examination and shortly afterwards he was appointed to the Hanlin Academy.
He subsequently rose through the ranks in the Qing civil service and served under the Kangxi, Yongzheng and Qianlong emperors.
Zhang was an upstanding civil service officer and highly praised for both his upright character and principled background.
Zhang was the only official to survive the battles of succession from Kangxi to Yongzheng to Qianlong, and was trusted by all three emperors.
However, Zhang made the mistake of seeking an audience with the emperor even before the edict rebuking him had reached his residence.