not fight in the battles. Zhang submitted an indictment accusing Sun of fraud. Sun was demoted to be a county magistrate, and Zhang was promoted in his stead, and sometime thereafter was made acting commandant at You Prefecture (幽州, roughly modern Beijing). When Eastern Tujue's khan Ashina Mochuo subsequently invaded and, after capturing Zhao (趙州, roughly modern Shijiazhuang, Hebei) and Ding (roughly modern Baoding, Hebei) Prefectures but then withdrew through You Prefecture, Zhang tried to intercept him, and in the battle suffered an arrow wound to the hand. Wu Zetian sent messengers to praise him and physicians to treat him. He was subsequently made the secretary general at Bing Prefecture (并州, roughly modern Taiyuan, Shanxi). During Emperor Zhongzong's second reign In 705, Wu Zetian was overthrown in a coup, and her son and crown prince Li Xian (Li Dan's older brother, also former emperor, who had replaced him as crown prince in 698) was restored (as Emperor Zhongzong). In 706, when Emperor Zhongzong was returning from Luoyang, which Wu Zetian had made capital, to the old Tang capital Chang'an, he made Zhang Rendan one of the commanding generals of the imperial guards and the acting secretary general of Luo Prefecture (洛州, i.e., Luoyang), in charge of Luoyang. At that time, grain was expensive at Luoyang, and there were many grain thieves. Zhang captured them and caned them to death, and after the bodies stacked up, no one dared to steal grain any more. In 707, after another Eastern Tujue incursion that saw the Tang general Shazha Zhongyi () defeated by Ashina Mochuo, Emperor Zhongzong commissioned Zhang to replace Shazha as the general in charge of the Shuofang region (i.e., northern Shanxi and northern Shaanxi). When he arrived at the army camp, Eastern Tujue forces were withdrawing, and he made a surprise attack against them, inflicting much losses. In 708, while Ashina Mochuo was busy fighting with Tuqishi () forces in the Western Regions (Xiyu), Zhang wanted to take advantage of Ashina Mochuo's absence to cross the Yellow River in the bend region (in modern western central Inner Mongolia), which had served as the de facto border of Tang and Eastern Tujue, and he submitted a proposal to build three forts north of the river to cut off the route that Eastern Tujue usually took in invading Tang territory. (Under the proposal, the eastern fort would be built in modern Hohhot;