In Polish military service, he was captured by Khmelnystsky's rebel Cossack forces at the Battle of Zhovti Vody in May 1648, he was freed on account of his education and experience and rose to become secretary-general or chancellor ("heneralny pysar") of the Cossacks and one of Khmelnytsky's closest advisors.