System.Perspective function use within Project Scripts

You’re probably going to have to restructure things a bit.

Basically, once you’re in a tag event script (as in, configured specifically on a tag, rather than a tag change script), you’ve “lost” the context of the Vision or Perspective window/view you were in.

I would recommend a somewhat different pattern.
Instead of writing to the tag, and then checking for some error condition, you should have your ‘validation’ logic in the project library, and have your barcode scan/text box simply invoke that shared project script. You can use the technique(s) described in this thread to throw a generic error back to either context.

That way you can ‘guarantee’ whatever value makes it onto the tag is validated, and simplify the logic in your tag event script (I would also recommend putting that code into a project script, as a general practice).