# Script Transform not updating properly in perspective session

**URL:** <https://forum.inductiveautomation.com/t/script-transform-not-updating-properly-in-perspective-session/63252>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [August 22, 2022, 4:20am UTC](https://forum.inductiveautomation.com/t/script-transform-not-updating-properly-in-perspective-session/63252 "2022-08-22T04:20:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sri\_Haran](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sri\_Haran](https://forum.inductiveautomation.com/u/Sri_Haran)\
**Post date:** [August 22, 2022, 4:20am UTC](https://forum.inductiveautomation.com/t/script-transform-not-updating-properly-in-perspective-session/63252/1 "2022-08-22T04:20:18Z")

</div>

Hello All,  
I’m using a Script transform in indirect tag binding the goal is to whenever a tag value not changed for more than 5 sec transform value should return InActive for this i have collected the timestamp of the tag and got the current timestamp using system.date.now() i compared both these time using system.date.secondsBetween(a,b) whenver the tag value not changed for five sec it’s not updating  
how to resolve this issue, Below is my code  
Thanks & Regards,  
Sri Haran

```
a=system.tag.read("[MQTT Engine]Data_Factory/Health/"+str(self.view.params.asset_code))
a=a.getTimestamp()
#	print(a)
b=system.date.now()
#	print(b)
time = system.date.secondsBetween(a,b)
if time <= 5 :
	return("Active")
elif 5< time <300:
	return ("InActive")
elif time >=300:
	return("InActive")
else:
	return("Error")

```

---

<div class="post-metadata">

**Author:** ![user77](https://avatars.discourse-cdn.com/v4/letter/u/a183cd/32.png) [@user77](https://forum.inductiveautomation.com/u/user77)\
**Post date:** [August 22, 2022, 5:10am UTC](https://forum.inductiveautomation.com/t/script-transform-not-updating-properly-in-perspective-session/63252/2 "2022-08-22T05:10:28Z")

</div>

I believe your script should work. I think the reason it may not appear to be working is the indirect tag binding.

If you have the binding on the tag you are trying to monitor your time value will always be zero. You will need to bind to something that is continually polling such as [System]Gateway/CurrentDateTime. You can also then use the tag value in your script by replacing b=system.date.now() with b = value

---

<div class="post-metadata">

**Author:** ![hayden](https://avatars.discourse-cdn.com/v4/letter/h/91b2a8/32.png) [@hayden](https://forum.inductiveautomation.com/u/hayden)\
**Post date:** [August 22, 2022, 6:13am UTC](https://forum.inductiveautomation.com/t/script-transform-not-updating-properly-in-perspective-session/63252/3 "2022-08-22T06:13:23Z")

</div>

As User77 says, the script should be okay, but you can verify it using the script console. But tag bindings will only trigger if the tag they are bound to changes. You can set your binding to an expression binding, for example:

```auto
timebetween(tag("Tag" + {parameter} + ".timestamp"),now(1000))

```

which will run the script every second (as an expression will run if any part of it changes) and return the time difference. You can then have an expression ‘if’ statement do the rest. For some reason, though I don’t if others have had this, I get performance issues if I use a lot of scripts for my tag bindings but expressions tend to work better.

---

<div class="post-metadata">

**Author:** ![Sri\_Haran](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sri\_Haran](https://forum.inductiveautomation.com/u/Sri_Haran)\
**Post date:** [August 22, 2022, 6:20am UTC](https://forum.inductiveautomation.com/t/script-transform-not-updating-properly-in-perspective-session/63252/4 "2022-08-22T06:20:42Z")

</div>

Hi All,  
I solved this by binding an direct tag of “[System]Gateway/CurrentDateTime” which will update for every second and then i changed my script slightly like this  
Thanks & Regards,  
Sri  
a=system.tag.read(“[MQTT Engine]Data\_Factory/Health/”+str(self.view.params.asset\_code))  
a=a.getTimestamp()  
# print(a)  
b=system.tag.read(“[System]Gateway/CurrentDateTime”)  
b= b.getTimestamp()  
# print(b)  
time = system.date.secondsBetween(a,b)  
if time \<= 5 :  
return(“Active”)  
elif 5\< time \<300 :  
return(“InActive”)  
elif time \>=300:  
return(“InActive”)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 22, 2022, 7:34am UTC](https://forum.inductiveautomation.com/t/script-transform-not-updating-properly-in-perspective-session/63252/5 "2022-08-22T07:34:35Z")

</div>

I think you could simplify this into an expression and map transform.

**Expression**

```auto
secondsBetween(
    tag(“[MQTT Engine]Data_Factory/Health/”+str(self.view.params.asset_code)),
    now(1000) // Update every second.
)

```

**Map transform**  
 ![Map transform](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/d/9db4f529f3186d738e0033cff355d9f5a0b4e938.png)

This should execute more quickly and efficiently than starting up a script.

Note the peculiar `[` include value and `(` exclude value syntax. Read more in the docs.  
[https://docs.inductiveautomation.com/display/DOC81/Map+Transform](https://docs.inductiveautomation.com/display/DOC81/Map+Transform)

Tips:  
You forgot to apply code formatting to your most recent post.  
“InActive” should probably be “Inactive”. It’s one word.

---

<div class="post-metadata">

**Author:** ![Sri\_Haran](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sri\_Haran](https://forum.inductiveautomation.com/u/Sri_Haran)\
**Post date:** [August 22, 2022, 11:51am UTC](https://forum.inductiveautomation.com/t/script-transform-not-updating-properly-in-perspective-session/63252/6 "2022-08-22T11:51:26Z")

</div>

This works fine for me  
Thanks For your suggestion @Transistor  
Regards,  
Sri
