Expression binding (on a session.custom property):
runScript('HistoryRetrieval1Day.getHistory', 0, {this.custom.startDate})
{this.custom.startDate}
is today's midnight date and typeOf({this.custom.startDate})
returns "Date".
HistoryRetrieval1Day script
def getHistory(dStartDate):
arrPaths = system.db.runNamedQuery('Retrieve UNS tag names')
paths = []
for p in arrPaths:
paths.append(p[0])
return system.tag.queryTagHistory(
paths,
startDate = dStartDate,
endDate = system.date.addDays(dStartDate, 1),
returnSize = -1,
aggregationMode = 'LastValue',
returnFormat = 'Tall'
)
Script console
d = system.date.addDays(system.date.midnight(system.date.now()), 0)
print d
HistoryRetrieval1Day.getHistory(d)
outputs
Sun Jul 06 00:00:00 BST 2025
Opt-Dataset [37262R ā
¹ 4C]
The problem
The expression binding returns Dataset[0 rows, 4 cols]
.
I'm probably missing something obvious. What is it?
Hmm.
I know this isn't your question but why do you use system.date.addDays(...., 0)
in your script console example?
I do not have the answer but it might help if you showed your startDate
binding ?
... why do you use system.date.addDays(...., 0)
... ?
So I could test yesterday by changing 0 to -1!
startDate binding is
midnight(now(0))
which should initialise it to today when the application first loads.
Thanks!
Yeah honestly I'm not sure.
The only thing I can think of that might have a different outcome is script console scopping.
Have you tried checking whether your Named Query Retrieve UNS tag names
returns the same data when it's called from the expression binding and when it's called from the script console ? (Unless you've specified a particular DB in your NamedQuery rather than use the Default database).
If this is good on your end, I'll let the true experts chime in then.
Yes, the DB is specified in the named query.
I too am thinking it's something funny with scoping. Let's see what comes up. Thanks.
Log the date from the function, see if there's something weird here.
Side note: you can use arrPath.getColumnAsList(0)
to get a column as list, instead of building it yourself.
Add the project name to the runNamedQuery
. Perspective is gateway scope.
2 Likes