An easier way is to use system.device.setDeviceHostname.
system.device.setDeviceHostname
Check out this topic, Indirect OpcItemPath - #12 by pturmel