system.date.addWeeks Variable Question

Im making a pm scheduler using the following script:

<today = system.date.now()
WeeksFromToday = system.date.addWeeks(today, 2)
system.tag.write("PM/DateCalc", WeeksFromToday)>

If I put a tag in for the "2" to make the week counter variable it gives me a:
Traceback (most recent call last):

File "event:actionPerformed", line 2, in

TypeError: addWeeks(): 2nd arg can't be coerced to int

Ignition v7.9.1 (b2017012511)
Java: Oracle Corporation 1.8.0_411

The variable im trying to use is an INT4

Are you reading the tag or just putting in a tag path? You will need to read the tag.

Something like this:

today = system.date.now()
weeks = system.tag.readBlocking(["week_tag_to_use"])[0].value
WeeksFromToday = system.date.addWeeks(today, weeks)
system.tag.write("PM/DateCalc", WeeksFromToday)
3 Likes

Thanks for the reply, are reading blocks just for strings or lists.

Block means it blocks the gui thread until the operation is complete, and it returns a list of values because it accepts multiple tag paths at a time.

It's not reading blocks, but blocking the thread while reading.

See the manual: https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-readBlocking

1 Like

Im still on 7.9, I tired the read function but it returns the same error.

In the future, you should mark the post with that tag. I'm taking care of it for you. This post also belongs in the Ignition category, not general discussion.

1 Like

In that case:

today = system.date.now()
weeks = system.tag.read("week_tag_to_use").value
WeeksFromToday = system.date.addWeeks(today, weeks)
system.tag.write("PM/DateCalc", WeeksFromToday)
2 Likes

You're awesome, it was the .value I was missing.

No sweat.

For 7.9 the manual on this is here: system.tag.read | Ignition User Manual

A tag read will return a QualifiedValue:

QualifiedValue - A qualified value. This object has three sub-members: value, quality, and timestamp.