expression, godan verb (-ru, irregular)
have occasion to do; have a chance to do
Used when an opportunity arises to do something, often while doing something else. The phrase is a set expression meaning 'there is an opportunity' or 'it is convenient to do something at the same time'.
東京に行くついでがあるなら、ぜひ会いましょう。
If you have occasion to go to Tokyo, let's definitely meet.
買い物のついでがあったので、ついでに郵便局
I had to go shopping, so I took the opportunity to stop by the post office as well.
ついでに is an adverb meaning 'while you're at it' or 'incidentally', used to add an action. ついでがある is a verb phrase meaning 'there is an opportunity', often used as a reason for doing something extra.
The word ついで (序で) originally meant 'order' or 'sequence', and the phrase ついでがある literally means 'there is a sequence/opportunity'. The exact historical derivation is uncertain, but it is now a fixed expression for having a convenient chance to do something.