At random, infrequent times, I get errors referencing script files. I've included a screen shot of an example for "shared.Tables" -- it occurs with other scripts.
It seems to happen most often with "valueChanged" (on change) and "onStartup" events.
I tried adding an explicit 'import' and the error is "ImportError: No module named shared"
Without the import, the error is "No global named shared"
If this is a valueChanged event on a tag, make sure that the project containing the "shared" scripting library is also defined as the gateway project library where the tag is defined.
This is my only suggestion, I'll let the experts chime in in case this does not solve your issue.
EDIT: I'm dumb, this is obviously a property change script, my bad but might be worth trying?...
The most likely explanation is just "it's a bug". An intermittent problem with otherwise identical code sounds like a race condition in the script initialization process. It would be interesting if you could correlate "times it didn't work" with "times changes were made to the project or project(s) in the Designer and saved". I have a suspicion they would be related to each other.
I would encourage you to contact Support - they may or may not have a fix, but if nothing else can collect more detailed information from you and help get this issue in front of the right development team to take a detailed look.