No, there is no way to query CUCM, your extensions on CUCM and UCON should be the same at all times to avoid this kind of issue. Here is what I normally do with variable length dial plan if that is what you are going to:
assume DNs are 8 digits long
define the DNs on CUCM as such (all DNs should normally be in the same partition, there is no reason to have them in different partitions unless you need to block calls from one site to another, keep in mind jtapi for example is not partition aware so this creates conflicts)
create translation patterns to allow local 4 digit dialing
define the extension in UCON as 8 digit extension in global partition, add alternate 4 digit partition in site specific partition to allow addressing via 4 digits
HTH,
Chris