Copy Previous Value to a Tag Not working in Scripting on my Laptop

Per Video : Not Writing . Per Manual too .
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
#print "tag =" + tag + " Path= " + tagPath
#If previousValue.value != currentValue.value and initialChange == False :
If previousValue != currentValue and initialChange == False :
#system.tag.writeBlocking(["[default]Last Value"], [previousValue.value])
paths = ["[default]CN_Tags/My Tag","[default]CN_Tags/Last Value"]
values = [currentValue.value,previousValue.value]
# Execute the write operation.
system.tag.writeBlocking(paths, values)

{ Please edit your topic to format the code properly. That is, highlight all of the code in the topic editor, then click the "preformatted text" button </> to add the formatting markers. }

In your code, you must not check previousValue before checking the initialChange flag, as you will get a null pointer exception (None value) if you access any member of previousValue when initialChange is True.

Also, do not compare initialChange to True or False. It is already a boolean, so just use it by itself if you want to check for true, or not initialChange to check for false.


Thanks pturmel, I have been working on a 32 bit SCADA system for over 10+ years.
Found this Ignition very sophisticated and trying to come up to speed.

This is the exact script I am running. **Still not writing with or without Boolean compare of Initial Change.

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):

If previousValue.value != currentValue.value and initialChange == False :
system.tag.writeBlocking(["[default]Last Value"], [previousValue.value])

I hate to be a broken record, but.. @NARASIMHA_CASTURI

Otherwise, the code you've posted is invalid python


You are accessing previousValue.value before checking initialChange. Fix that first. And edit your posts to format your code as requested. We cannot see your indentations or other potential mistakes without the proper formatting.

Thank you Nick and pturmel . Attached my script screen shot. It appears same as that of training videos but checking the boolean first in mine per your advice. Still not writing previous value to Last Value tag. both tags are Read/Writable.

it needs to be indented under the def

def valueChanged....
    if not initialChange....


Note that, if you had formatted the code you posted as requested, this would have been a shorter conversation. :wink:


Thank you Jordan for good catch. (Migrating from basic 4 case insensitive /no indention code. haha. forgive me.) .

But still not working as expected. Corrected indent and code pretty much same as that of your screenshot .

There may be something in the gateway log that would provide a clue.

Yes Jordan, the 'false' was corrected to 'False' . still no good . sorry

([CN_Tags]My Tag, valueChanged) Error executing tag event script: Traceback (most recent call last): File "tagevent:valueChanged", line 2, in valueChanged NameError: global name 'false' is not defined. I am changing the tag value but no Log now .

Can you fix the code formatting in the earlier posts as suggested? It may help. Make it easy for us to help you!
Select the code and hit the </> button.

1 Like

You've gone back to you're original script.

Try this:

def valueChanged(tag,tagPath,previousValue,currentValue,initialChange,missedEvents):
    if not initialChange and previousValue.value != currentValue.value:
        system.tag.writeBlocking(['[default]Last Value'],[previousValue.value])

What exactly are you expecting to happen that isn't?

Is CN_Tags the default tag provider? Is the Last Value tag really a part of the default tag provider?

I surely check when I get back home
Thanks a lot

both 'My Tag' and 'Last Value' tags belong to same Tag Group ('Default')

I stick the code you sent me ( with indent and single quote for string)

Gateway is Running
Still NOT writing to Last Value when I change the value of My Tag

Note that Tag Group is not the same thing as Tag Provider.

I asked because you posted this:

That clearly shows that My Tag is in the Tag Provider CN_Tags. That is not the same as the default tag provider. The same thing can be seen on the screen shots of the tag editor that you have shown.

What happens if you try this:

def valueChanged(tag,tagPath,previousValue,currentValue,initialChange,missedEvents):
    if not initialChange and previousValue.value != currentValue.value:
        system.tag.writeBlocking(['[CN_Tags]Last Value'],[previousValue.value])

There is nothing syntactically wrong with the script, which means we need to look elsewhere, the most obvious place is the tag provider.

Can you show a snipit of the tag browser in the designer so we can see which tag provider is being used? Something like this:

1 Like

It is working NOW after putting in default tag provider

But still not working in CN_tags provider
tag path from right click:
[CN_Tags]My Tag
[CN_Tags]Last Value

I think I will put this to rest.

Thanks for all your help

it is indeed a sophisticated SCADA

Just last question?
In Automotive Industry : Can IGN track a Carrier and Vehicle Combo to Route to A or B lane based on some attribute Value ?? I am kind of new to IGN and like to know .

Is there any error in the tag diagnostics for the one that isn't working? (heartbeat icon in the top right array of icons in the tag editor in that screenshot) If scripts produce errors, then they'll show up in there

From your second screenshot, the one that isn't working, the tag script isn't enabled (top right check box)


Yes Sir, you are right. I enabled and it is good. thanks

@NARASIMHA_CASTURI , are you familiar with the ability to edit?

If you click the pencil icon at the bottom of one of your posts, it will allow you to edit it.

I think everyone is trying to politely point out that it's a lot easier to help someone out when you can see the code in its proper formatting. It also shows the indentation, which can make a difference in Python.

if False:
print "Hi"
print "Hello World"


if False:
	print "Hi"
print "Hello World"

Why isn't my code working? It's because I didn't indent the last line, but you can't necessarily tell that when the format isn't shown. (edit: It's also a lot easier to read. Also, "False" needed to be capitalized. Whoops, this is why editing is great.)