[verb (dictionary form)] + ついでに [verb た-form] + ついでに [noun] + の + ついでに
ついでに means "while you're at it": you are doing one thing anyway, and you use the chance to do a second, smaller thing as well. The main action comes first, in the dictionary form, the た-form, or as a noun with の.
The dictionary form puts the second action on the way or during the first. The た-form puts it after the first is done, once you are already there.
What follows ついでに is the extra, not the purpose of the trip. Swap the two and the sentence says something else: the first sentence below is a trip to the bank, the second a trip for the dry cleaning.
For the same reason, asking a favour with ついでに makes it sound small. That suits "grab me a drink while you're up", but not a real request.
At the start of a sentence, ついでに means "while I'm at it" or "by the way", adding one more thing to what was just said.