# \[Perspective\] Scripting using DateTimeInput.prop

**URL:** <https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 25, 2022, 5:18pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021 "2022-05-25T17:18:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [May 25, 2022, 5:18pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/1 "2022-05-25T17:18:11Z")

</div>

I have a script in the project library that runs at a set interval on the gateway script. Im looking to use a date input selector component in the script to set a date time. Currently its set to a fixed last 3 hours. i can find any doc about using component property’s in script lang. I need to use the tag value.

Example :

```auto
    end = DateTimeInput.props.value
	start = DateTimeInput_0.props.value
	
	data = system.tag.queryTagCalculations(paths, calc, start,end)

```

Current Code :

```auto
    end = system.date.now()
	start = system.date.addHours(end,-3)
	
	data = system.tag.queryTagCalculations(paths, calc, start,end)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 25, 2022, 5:46pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/2 "2022-05-25T17:46:43Z")

</div>

> [@byrcharl](#):
>
> runs at a set interval on the gateway script

Gateway timer scripts don't have any access to a user interface. Possibly you need a user interface that will place a date-time into a tag, and the timer script can access that tag.

---

<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:** [May 25, 2022, 5:50pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/3 "2022-05-25T17:50:37Z")

</div>

You can’t use a component’s properties in a gateway script for a couple of reasons:

1. If there are no client views active there _is_ no component to read properties from.
2. If there were two client views active then which would determine the property?

Instead …

- Create a memory tag with a sensible name that relates to the project.
- Set its _Data Type_ to `DateTime`.
- Create a view with a date picker and bind this to the tag bidirectionally (so that it can both update the tag and can itself be updated if another client changes the tag).

Then you can read the tag value using `system.tag.readBlocking(["My/Tag/Path"])`.

See [Reading and Writing to Tags - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/Reading+and+Writing+to+Tags) for more.

---

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [May 25, 2022, 8:55pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/4 "2022-05-25T20:55:20Z")

</div>

I set this up but im still getting an error.

CODE :

```auto
    end = system.tag.readBlocking(["[default]AFE1/End"])
	start = system.tag.readBlocking(["[default]AFE1/Start"])
	
	data = system.tag.queryTagCalculations(paths, calc, start,end)

```

Error:

```auto
Traceback (most recent call last):
  File "<TimerScript:AFE_ANDON_MONITOR/AST @1,000ms >", line 1, in <module>
  File "<module:AFE1_AST_Time>", line 27, in AST
	at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1422)
	at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.coerce(PyArgumentMap.java:130)
	at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:82)
	at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:40)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractTagUtilities.queryTagCalculations(AbstractTagUtilities.java:643)
	at jdk.internal.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value '[[Thu May 26 00:06:00 PDT 2022, Good, Wed May 25 13:46:20 PDT 2022 (1653511580527)]]' into type: class java.util.Date

8.1.3 (b2021030309)
Azul Systems, Inc. 11.0.9

```

 ![2022-05-25_13-55-52](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/e/0e863d2ee68c49fa15bbf085bc9f4b93003384b9.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 25, 2022, 8:57pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/5 "2022-05-25T20:57:45Z")

</div>

> Reading a Tag from a script is accomplished with the `system.tag.readBlocking()` function, which requires the Tag path you wish to read from. This function returns a 'Qualified Value'; this object is more than just the value. A Qualified Value is the Tag value that has three attributes; Value, Quality, and TimeStamp.

[https://docs.inductiveautomation.com/display/DOC81/Scripting+Object+Reference#ScriptingObjectReference-QualifiedValue](https://docs.inductiveautomation.com/display/DOC81/Scripting+Object+Reference#ScriptingObjectReference-QualifiedValue)

---

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [May 25, 2022, 9:13pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/6 "2022-05-25T21:13:48Z")

</div>

so it should be something like.

```auto
end = system.tag.readBlocking(["[default]AFE1/End"]).getValue()

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 25, 2022, 9:17pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/7 "2022-05-25T21:17:19Z")

</div>

Add a `[0]` in there. The function returns a _ **list of** _ Qualified Values.

---

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [May 25, 2022, 9:19pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/8 "2022-05-25T21:19:31Z")

</div>

Ok not sure if this is correct … the attribute is not found. Is there somthing i need to import for this function?

```auto
end = system.tag.readBlocking(["[default]AFE1/End"]).getValue([0])

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 25, 2022, 9:22pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/9 "2022-05-25T21:22:50Z")

</div>

> [@Using system.tag.readBlocking and turning into string](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/12):
>
> Let’s start from first principles. When you use [system.tag.readBlocking](https://docs.inductiveautomation.com/display/DOC81/system.tag.readBlocking), the return value is a list of [QualifiedValue](https://docs.inductiveautomation.com/display/DOC81/Scripting+Object+Reference#ScriptingObjectReference-QualifiedValue) objects. To extract the first element of the list, use subscript 0 to retrieve the first element: qualifiedValue = listOfValues[0]. Now you have a QualifiedValue object. To retrieve the actual value, which can be any type, use getValue(), or, better, .value: actualValue = qualifiedValue.value. The type of value at this point will be whatever the tag’s type is, per @josborn’s p…

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 25, 2022, 9:24pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/10 "2022-05-25T21:24:40Z")

</div>

```auto
end = system.tag.readBlocking(["[default]AFE1/End"])[0].getValue()

```

Since readBlocking takes a list, and returns a list, consider using one call to get both QVs. Then apply the `.value` where you use them.

Something like this:

```auto
startQV, endQV = system.tag.readBlocking(["[default]AFE1/Start", "[default]AFE1/End"])
data = system.tag.queryTagCalculations(paths, calc, startQV.value, endQV.value)

```

The first line use python’s tuple packing/unpacking syntax to assign elements of a list to individual variables. The last line uses jython’s automatic recognition of NetBeans getter methods as properties. This is more efficient that calling the `.getValue()` method itself.

---

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [May 25, 2022, 9:51pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/11 "2022-05-25T21:51:05Z")

</div>

Yes thank you this makes more since . i have yet to need to structure my scripts this way haha . thanks should make it way easier now i know i can lay it out this way

---

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [May 28, 2022, 3:16pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/12 "2022-05-28T15:16:17Z")

</div>

So this changed the Index on me … the dataset is now different . i cant use. I get an error stating index out of bounds.  
Code :

```auto
system.tag.writeBlocking("[default]AFE1/Assistance Beacons/INDUCTS/AST_IND1_2",str(data.getValueAt(0,1)/60))

```

Error:

```auto
java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0

```

---

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [May 28, 2022, 3:25pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/13 "2022-05-28T15:25:18Z")

</div>

Full Script:

```auto
import system
def AST():	# Build a list of String tag paths
	paths = [
				"[default]AFE1/Assistance Beacons/INDUCTS/LT_AST_IND1",
				"[default]AFE1/Assistance Beacons/INDUCTS/LT_AST_IND2",
				"[default]AFE1/Assistance Beacons/INDUCTS/LT_AST_IND3",
				"[default]AFE1/Assistance Beacons/INDUCTS/LT_AST_IND4",
				"[default]AFE1/Assistance Beacons/INDUCTS/LT_AST_IND5",
				"[default]AFE1/Assistance Beacons/INDUCTS/LT_AST_IND6",
				"[default]AFE1/Assistance Beacons/INDUCTS/LT_AST_IND7",
				"[default]AFE1/Assistance Beacons/INDUCTS/LT_AST_IND8",
				"[default]AFE1/Assistance Beacons/INDUCTS/LT_AST_IND9",
				"[default]AFE1/Assistance Beacons/INDUCTS/LT_AST_IND10"
			]
	 
	# Determine the calculation to use
	calc = ["DurationOn"]
	 
	# Define the date range
	#end = system.date.now()
	#start = system.date.addHours(end,-3)
	
	startQV,endQV = system.tag.readBlocking(["[default]AFE1/Start", "[default]AFE1/End"])
	data = system.tag.queryTagCalculations(paths, calc, startQV.value, endQV.value)
	#start = system.tag.readBlocking("[AFE1/Start]")[0].value
	
	# Run the query, returning the results as an Ignition dataset
	#data = system.tag.queryTagCalculations(paths, calc, start,end)
	 
	# From here you would need to do something useful with the data variable. You could extract the values
	# and write them to a tag, pass them to a dataset property on a component, or any number of other things.
	
	system.tag.writeBlocking("[default]AFE1/Assistance Beacons/INDUCTS/AST_IND1_2",str(data.getValueAt(0,1)/60))
	system.tag.writeBlocking("[default]AFE1/Assistance Beacons/INDUCTS/AST_IND3_4",str(data.getValueAt(1,1)/60))
	system.tag.writeBlocking("[default]AFE1/Assistance Beacons/INDUCTS/AST_IND5_6",str(data.getValueAt(2,1)/60))
	system.tag.writeBlocking("[default]AFE1/Assistance Beacons/INDUCTS/AST_IND7_8",str(data.getValueAt(3,1)/60))
	system.tag.writeBlocking("[default]AFE1/Assistance Beacons/INDUCTS/AST_IND9_10",str(data.getValueAt(4,1)/60))
	system.tag.writeBlocking("[default]AFE1/Assistance Beacons/INDUCTS/AST_IND11_12",str(data.getValueAt(5,1)/60))
	system.tag.writeBlocking("[default]AFE1/Assistance Beacons/INDUCTS/AST_IND13_14",str(data.getValueAt(6,1)/60))
	system.tag.writeBlocking("[default]AFE1/Assistance Beacons/INDUCTS/AST_IND15_16",str(data.getValueAt(7,1)/60))
	system.tag.writeBlocking("[default]AFE1/Assistance Beacons/INDUCTS/AST_IND17_18",str(data.getValueAt(8,1)/60))
	system.tag.writeBlocking("[default]AFE1/Assistance Beacons/INDUCTS/AST_IND19_20",str(data.getValueAt(9,1)/60))

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 28, 2022, 3:26pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/14 "2022-05-28T15:26:10Z")

</div>

That means you got a result with no rows. You need to check for that before using `data`. Consider writing it to a dataset memory tag so you can look at it while debugging.

---

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [May 28, 2022, 3:27pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/15 "2022-05-28T15:27:12Z")

</div>

I was just searching for a way to see what is in the dataset.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 28, 2022, 3:29pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/16 "2022-05-28T15:29:05Z")

</div>

I also recommend you not use so many `.writeBlocking` calls. Built a list of the target paths, and a list of the computed values. Then you can call `.writeBlocking` once. Much more efficient. Something like this:

```auto
writePaths = ["[default]AFE1/Assistance Beacons/INDUCTS/AST_IND1_%d" % (2*r+2) for r in range(data.rowCount)]
writeValues = [str(data.getValueAt(r, 1)/60) for r in range(data.rowCount)]
system.tag.writeBlocking(writePaths, writeValues)

```

---

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [May 28, 2022, 3:29pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/17 "2022-05-28T15:29:59Z")

</div>

yes i haven’t refined it yet

---

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [May 28, 2022, 3:35pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/18 "2022-05-28T15:35:19Z")

</div>

> [@pturmel](#):
>
> ```auto
> writePaths = ["[default]AFE1/Assistance Beacons/INDUCTS/AST_IND1_%d" % (2*r+2) for r in range(data.rowCount)]
> writeValues = [str(data.getValueAt(r, 1)/60) for r in range(data.rowCount)]
> system.tag.writeBlocking(writePaths, writeValues)
> 
> ```

Thank you . for the index out of range i had my start and end time reversed i have data now .

---

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [May 28, 2022, 4:35pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/19 "2022-05-28T16:35:36Z")

</div>

ok can we talk about this part is it regex . I kinda get how it work but say i want to skip by odd numbers . r+2 ya ?? I tried that but still was only placing in the 2 to 5 tag . i ended up just renaming my tags but for future reference.

```auto
%d" % (2*r+2)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 28, 2022, 5:54pm UTC](https://forum.inductiveautomation.com/t/perspective-scripting-using-datetimeinput-prop/60021/20 "2022-05-28T17:54:52Z")

</div>

`r` starts with zero, then one, continuing while `r` is less than the value supplied to `range()`. You want the interval to be by twos, so multiply by two. The first to be two, so add two.
