# Cannot Convert String to Java INT

**URL:** <https://forum.inductiveautomation.com/t/cannot-convert-string-to-java-int/90880>\
**Category:** Ignition\
**Tags:** scripting, ignition81\
**Created:** [May 24, 2024, 3:37pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-string-to-java-int/90880 "2024-05-24T15:37:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [May 24, 2024, 3:37pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-string-to-java-int/90880/1 "2024-05-24T15:37:11Z")

</div>

I have this script that creates a dataset. Runs fine in the script console with the same path provided, but I get an type conversion error when using `runScript()` on an expression dataset tag.

```python
def getDistributorDropdownDataset(path):
	'''
		Get the position values and strings and return it as a dataset for use in a dropdown selector.
		
		Args:
			path	(string)	:	string path to the dataset for the dropdown data
			
		Returns:
			dataset	(dataset)	:	dataset of options
	'''
	parentTagPath = path.rsplit('/',1)[0]
	tagsToRead = [parentTagPath+'/'+str(num) for num in range(1,17)]
	
	destinations = [tag.value for tag in system.tag.readBlocking(tagsToRead)]
	
	headers = ['POS', 'DEST']
	data = []
	
	for i, destination in enumerate(destinations):
		data.append([i+1, destination])
		
	return system.dataset.toDataSet(headers, data)

```

Cannot convert "path" into into type: class java.lang.Integer

Why is it trying to convert the path into an integer? Where, even?

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [May 24, 2024, 4:12pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-string-to-java-int/90880/2 "2024-05-24T16:12:21Z")

</div>

me too I can't see error 😆  
Show us logs (error line)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 24, 2024, 4:33pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-string-to-java-int/90880/3 "2024-05-24T16:33:05Z")

</div>

I would have to assume that one of the tag's that you're reading's value is actually "path" (unfortunate that it matches the function parameter name). Generally, you'll see this type of error when creating a dataset if the values in your data list are not of the same types.

The `to*DataSet()` functions will assume the type of the value in the first row for that column.

So for instance, if the first tag value is an integer, then the column will be typed as an integer column. If then next value is a string, you will get this error.

If you have a mix of integer values and string values then you will need to use the DatasetBuilder to explicitly specify that the column type should be String.

```python
from com.inductiveautomation.ignition.common.util import DatasetBuilder
from java.lang import Integer, String

def getDistributorDropdownDataset(path):
    parentTagPath = path.rsplit('/',1)[0]
    tagsToRead = [parentTagPath+'/'+str(num) for num in range(1,17)]
	
    destinations = [tag.value for tag in system.tag.readBlocking(tagsToRead)]

    builder = DatasetBuilder.newBuilder()
    builder.colNames(["POS","DEST"])
    builder.colTypes([Integer, String])

    for i, destination in enumerate(destinations):
        builder.addRow(i,destination)

    return builder.build()

```

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [May 24, 2024, 5:47pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-string-to-java-int/90880/4 "2024-05-24T17:47:02Z")

</div>

The path is not actually "path" that's just pseudo-code.

It makes less that 0 sense that it works in the script console but not from the `runScript()`

The very first row is Integer, String. I've even added type conversions just to be sure.

```python
def getDistributorDropdownDataset(path):
	'''
		Get the position values and strings for a distributor and return it as a dataset for use in a dropdown selector.
		
		Args:
			path	(string)	:	string path to the dataset for the dropdown data
			
		Returns:
			dataset	(dataset)	:	dataset of options
	'''
	parentTagPath = path.rsplit('/',1)[0]
	tagsToRead = [parentTagPath+'/'+str(num) for num in range(1,17)]
	
	destinations = [str(tag.value) for tag in system.tag.readBlocking(tagsToRead)]
	
	headers = ['POS', 'DEST']
	data = []
	
	for i, destination in enumerate(destinations):
		row = [int(i+1), destination]
		print row
		data.append(row)
		
	return system.dataset.toDataSet(headers, data)

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/7/e7be5c0ce271a7871fc7542d5cd5614abfaa8f32.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/9/f9ac8282952c1c553b5e99be3fb0ad40fc1f7c26.png)

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [May 24, 2024, 5:49pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-string-to-java-int/90880/5 "2024-05-24T17:49:33Z")

</div>

~~You're using a tag path there as if it's going to give you tag value.~~  
Edit: Wow i need coffee  
Edit Edit: Wait no, the error explicitly states the value it's attempting to coerce, which looks like a tag path.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 24, 2024, 5:49pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-string-to-java-int/90880/6 "2024-05-24T17:49:34Z")

</div>

That error is not being generated by your script, it's in the evaluation of the expression.

Show your expression.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [May 24, 2024, 5:53pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-string-to-java-int/90880/7 "2024-05-24T17:53:41Z")

</div>

Just figured that out.

Legacy call works like this

```python
runScript('Grain.Data.getDistributorDropdownDataset("'+{[.]DropdownData.path}+'")')

```

(I have a custom string property "path"

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 24, 2024, 5:57pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-string-to-java-int/90880/8 "2024-05-24T17:57:19Z")

</div>

Yeah, that should work.

The preferred syntax would be:

```python
runScript('Grain.Data.getDistributorDropdownDataset',0,{[.]DropdownData.path})

```

Feels odd to me to be keeping dropdown data in a tag, as opposed to a top level script variable, but I'm sure you have your reasons.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [May 24, 2024, 6:02pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-string-to-java-int/90880/9 "2024-05-24T18:02:29Z")

</div>

What's the "0" ?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 24, 2024, 6:04pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-string-to-java-int/90880/10 "2024-05-24T18:04:27Z")

</div>

The poll rate. Looking at the preferred syntax:  
`runScript(scriptFunction, [pollRate],[arg1],[arg2],[arg...])`

So, if you need to pass any arguments, you need to specify a poll rate.
