Page 1 of 1

GetPrivateData Iteration

Posted: Thu Mar 07, 2019 2:49 am
by SunDev
I am trying to iterate through the collection/array and get the values that comes back from the getPrivateDataTags on the Job object using VbScript. I'm running into an issue. Whatever I do, I cannot iterate through the collection or get any values from the collection that comes back. I have tried multiple different methods to get the value from the returned array but no go. Any help here would be greatly appreciated.

datatags = job.getPrivateDataTags()
Call job.Log(MESSAGELEVEL_DEBUG, TypeName(datatags)) 'This works. String() is the response
Call job.Log(MESSAGELEVEL_DEBUG, Ubound(datatags)) 'This works. 6 is the response
Call job.Log(MESSAGELEVEL_DEBUG, CStr(datatags(1))) 'Doesn't work
for index = 0 to ubound(datatags)
Call job.Log(MESSAGELEVEL_DEBUG, CStr(datatags.Item(index))) 'Doesn't work
Next

Re: GetPrivateData Iteration

Posted: Thu Mar 07, 2019 6:20 pm
by SunDev
In case other people have experienced this. After extensive digging I have found that the object returned from getPrivateDataTags cannot be read via vbscript.

Example:
datatags = job.getPrivateDataTags()
Call job.Log(MESSAGELEVEL_DEBUG, TypeName(datatags)) 'This works. String() is the response
Call job.Log(MESSAGELEVEL_DEBUG, Ubound(datatags)) 'This works. 6 is the response

If you run this VarType(datatags) it returns 8200.

Vbscript can't work with arrays that are not a variant array. The return of VarType(myarray) should be 8192 or 8204 otherwise Vbscript won't work. The object from above returns a strongly typed String(). So VbScript can't read the values although some methods will work on it (Example: UBound). This is probably true for other methods on the job and switch classes.

Re: GetPrivateData Iteration

Posted: Fri Mar 08, 2019 3:46 pm
by gabrielp
Thanks for following up with the solution! If it helps anyone else, here is a snippet of code I used previously to iterate over private data tags using JS: https://github.com/open-automation/swit ... js#L53-L65