Hi David
The UID is assigned when the schedule is set up during the train planning process. The best way to find it out is to use the schedule files available on the NR Open Data platform. They contain everything that's planned, and you can select the one you need by mapping the CRS code to a TIPLOC, and searching for a train at a location with one of the TIPLOCs.
For context, what're you trying to do here? There may be a more straightforward method of getting there other than working out the UID.
Peter