Call global script from UDT tag value change event

Hi all,

Trying to work out the best way to handle some scripting…

I have a UDT for an AB Logix PLC, which handles diagnostic information and also has date and time information from the PLC in it. This tag structure also has the ability to store a new date and time, and then send it back to the PLC to set the PLC time. This UDT structure is all working well.

Next, I have a script which is currently stored in the project script library. I pass it a tag path to one of those UDT instances, and it gets the current PC time and synchronises the target PLC clock with that PC time. I can call this script using a button on a client, which works just fine.

But here’s where my current approach doesn’t work. Within the UDT, I’ve got a bool tag called “AutoSyncEnable”, and two int tags “AutoSyncHour” and “AutoSyncMinute”. The idea is that if Auto Sync is enabled, it will automatically sync the PLC time at [AutoSyncHour]:[AutoSyncMinute] every day. To trigger this, I have a tag change event on the CurrentMinute tag - so every time the PLC clock’s minute changes, I will check if Auto Sync is enabled, and if so, whether it’s the right time to do the Auto Sync. If it is, I call the same script as before. However, I’ve learned that I can’t call a project library script from a UDT tag value change event.

I could just duplicate the script right there in the UDT definition, as it’s only writing to other tags within that UDT anyway - but as soon as I find myself copying and pasting a script, I start to think that maybe I should be doing this differently. Any suggestions?

See discussion here about this related topic:

Error Running Project Script: “project not defined”

2 Likes

Thanks. Solution (as found in that link) was to move the script to a shared script, not a project script. This makes a lot of sense anyway, as this is a very generic script that will ultimately be used on every PLC that’s added to the system

1 Like

Excuse my ignorance, but what is a Shared Script?

In v7.9, tag events are “outside” any project and can only use scripts in the “shared” namespace. This architecture was changed in v8.x to the “Global Scripting Project”. In v8.x, all scripts are in projects, with a designated project serving non-project elements (tags).

Thank you but I found my answer.

https://docs.inductiveautomation.com/display/DOC81/7.9+to+8.1+Upgrade+Guide

look at “Project Inheritance & “Global” Upgrade Logic”

A Shared Script was a script that was written in the “global” project in 7.9 which all projects inherited from directly. in 8.x this was changed so that projects must explicitly specify their parent project for inheritance. In order not to break projects being upgrade from 7.9 to 8.x, a project called “global” was created during the upgrade and all existing projects would have that set as their parent.