In ARCHICAD 19 several of the new Labels (e.g "Identification Label 19") do use the Master ID (they can display the Compact ID - ID without the Master ID prefix - , Master ID or Full ID (content of Master ID + Compact ID).
You may check their scripts to see how they do it.
There is also a post about this:
http://archicad-talk.graphisoft.com/viewtopic.php?p=235152#235152
He says you need at least AC18 build 4020 for it to work.
Loving Archicad since 1995 - Find Archicad Tips at x.com/laszlonagy
AMD Ryzen9 5900X CPU, 64 GB RAM 3600 MHz, Nvidia GTX 1060 6GB, 500 GB NVMe SSD
2x28" (2560x1440), Windows 10 PRO ENG, Ac20-Ac27