# KeyError dataset tag to pydataset for cross ref

**URL:** <https://forum.inductiveautomation.com/t/keyerror-dataset-tag-to-pydataset-for-cross-ref/62783>\
**Category:** Ignition\
**Created:** [August 8, 2022, 3:59pm UTC](https://forum.inductiveautomation.com/t/keyerror-dataset-tag-to-pydataset-for-cross-ref/62783 "2022-08-08T15:59:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [August 8, 2022, 3:59pm UTC](https://forum.inductiveautomation.com/t/keyerror-dataset-tag-to-pydataset-for-cross-ref/62783/1 "2022-08-08T15:59:02Z")

</div>

getting a KeyError when tring to get a value from a dataset tag to cross ref a a user input/location.

```auto
Traceback (most recent call last):
  File "<event:actionPerformed>", line 31, in <module>
KeyError: XV_213003

	at org.python.core.Py.KeyError(Py.java:225)
	at org.python.core.PyObject. __getitem__ (PyObject.java:655)
	at org.python.pycode._pyx7.f$0(<event:actionPerformed>:39)
	at org.python.pycode._pyx7.call_function(<event:actionPerformed>)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1275)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:631)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:590)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:170)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:265)
	at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
	at com.sun.proxy.$Proxy31.actionPerformed(Unknown Source)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

Ignition v7.8.5 (b2016120813)
Java: Oracle Corporation 1.8.0_271

```

relevant code

```auto
    #Dictionary to place valve location dataset in.
    CRvalveTo = {}
    #Dataset of valve locations
    ValveDataset = system.dataset.toPyDataSet(system.tag.read("System1/Project1/HOA/Valves").value)
    #Puts dataset into a dict
    for rowRead in ValveDataset:
        CRvalveTo[rowRead['id']] = rowRead['description']
    #Gets transfer location
    valveCrossx = CRvalveTo[valve]

```

---

<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:** [August 8, 2022, 4:01pm UTC](https://forum.inductiveautomation.com/t/keyerror-dataset-tag-to-pydataset-for-cross-ref/62783/2 "2022-08-08T16:01:30Z")

</div>

We can’t match line numbers up, since you didn’t post all your code, but the only line of the posted code that can error on the missing key `XV_213003` would be this one:  
`valveCrossx = CRvalveTo[valve]`

Indicating that your dictionary is not being populated with the values you expect it to. Consider printing your dictionary out before attempting to extract a value, so you can sanity check your script that’s filling it with data.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [August 8, 2022, 4:16pm UTC](https://forum.inductiveautomation.com/t/keyerror-dataset-tag-to-pydataset-for-cross-ref/62783/3 "2022-08-08T16:16:58Z")

</div>

@paul-griffith below is the full code:  
I’m having trouble printing the pydataset from the dataset tag in the scripting console.

```auto
# Gets Valve
valve = event.source.parent.getComponent('Label').text
# List of vales with multiple locations. 
ValveMultLocs =["AB_211220","XV_211102","AB_210720","XV_210402","XV_210502","XV_210102","XV_211002","XV_210603","XV_210803","XV_210903"]
if valve in ValveMultLocs:
    # Get Tank Number
    GetTank = event.source.parent.parent.Page
    # Read the selected Transfer To for apropriate tank
    TransferTo = system.tag.read("System1/Project1/Tank Details/"+GetTank+"/TransferTo").value
    # validate transfer
    message = "Do you want to open" + GetTank + "to" + TransferTo
    system.gui.messageBox(message)
    # ask user to verify transfer location
    UserInputTransfer = system.gui.showTouchscreenKeyboard("Verify Transfer Location")
    if UserInputTransfer == TransferTo:
        message = GetTank + " will now open to " + TransferTo 
        system.gui.box(message)
        value = event.source.Setvalue
        event.source.parent.Set_tag_state = value
    else:
        system.gui.messageBox("Transfer input did not match Tank Details selection.")
else:
    #Dictionary to place valve location dataset in.
    CRvalveTo = {}
    #Dataset of valve locations
    ValveDataset = system.dataset.toPyDataSet(system.tag.read("System1/Project1/HOA/Valves").value)
    #Puts dataset into a dict
    for rowRead in ValveDataset:
        CRvalveTo[rowRead['id']] = rowRead['description']
    #Gets transfer location
    valveCrossx = CRvalveTo[valve]
    UserInputTransfere = system.gui.showTouchscreenKeyboard("Verify Transfer Location")
    if UserInputTransfere == valveCrossx:
        message = valve + " will now open to " + valveCrossx 
        system.gui.messageBox(message)
        value = event.source.Setvalue
        event.source.parent.Set_tag_state = value
    else:
        system.gui.messageBox("Transfer input did not match Tank Details selection.")

```
