Outbound Routes - add Account code into Dial pattern

Hi Community,

I have a FreePBX server connected with a different PBX via SIP Trunk. The other PBX requires a Account code in the dial string for accounting purpose. At the moment I have for every Caller ID in the system the following dial pattern in the outbound route of the trunk:

Prepend Prefix match Pattern CallerID
*49 0000# [1]XXXXXXX 100
*49 0203# [1]XXXXXXX 101

This is just an example for the dial patterns. When Extension 100 calls an US number his account code 0000 (with a starting *49 and ending #) gets added into the dial string. Caller ID 101 has the account number 0203 and this number woudl be added to the dial number. That works fine and the receiving PBX can see the account code. However, instead of manual adding for each extension the dial pattern I would like to have script that is getting the account number for the extension from the account field in the extension properties and adding the account number automatically to the outgoing dial string.
Does anyone has an ideas how this can be done?