# KeyError In Script

**URL:** <https://forum.inductiveautomation.com/t/keyerror-in-script/20494>\
**Category:** Ignition\
**Created:** [November 1, 2018, 8:38pm UTC](https://forum.inductiveautomation.com/t/keyerror-in-script/20494 "2018-11-01T20:38:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jciatti](https://avatars.discourse-cdn.com/v4/letter/j/3da27b/32.png) [@jciatti](https://forum.inductiveautomation.com/u/jciatti)\
**Post date:** [November 1, 2018, 8:38pm UTC](https://forum.inductiveautomation.com/t/keyerror-in-script/20494/1 "2018-11-01T20:38:02Z")

</div>

Hi there,

I"m getting an error in a script that I imported from a running HMI System into a development system. The script itself is being called as required but I am getting an error that says “KeyError: FACEPLATES\_ADE\_00”. I have the dataset FACEPLATES\_ADE\_00 created in my project, so I’m not sure how to go about testing what is wrong.

Here is the set of script that is throwing the error:

```auto
if action == "OPEN":
		for ea in dict_faceplates['FACEPLATES_ADE_00']: # # Iterate the globally defined dataset
			if ea['UDT'] == udtParent:
				# General Parameters
				fpParam['SelectedTab'] = 0
				fpParam['DeviceTag'] = event.source.DeviceTag
				# Add any additional faceplate specific parameters below here
																							
				if (ea['UDT'] == "ADE_00/ADE_E_HIC") or (ea['UDT'] == "ADE_00/ADE_E_PID"): # Append additional parameter for PID blocks
					if not event.source.DeviceTagAI == '':
						# TEMP CODE TO UPDATE UDT
						if system.tag.read( tag+'/HMI/CFG/DeviceTagAI' ).value == '':
							system.tag.editTag(
								tag,
								parameters={"HMICFG_DeviceTagAI":event.source.DeviceTagAI})									
				# Call the window activate command
				SYS_02.GlobalFaceplateActivate(ea['fpName'], ea['fpDest'], fpParam, action="SWAP")
				return True

```

Any help would be appreciated. I’m not really clear on where to start troubleshooting this.

---

<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:** [November 1, 2018, 8:42pm UTC](https://forum.inductiveautomation.com/t/keyerror-in-script/20494/2 "2018-11-01T20:42:36Z")

</div>

> [@jciatti](#):
>
> for ea in dict\_faceplates['FACEPLATES\_ADE\_00']:

This isn't the entire script, but the KeyError is being thrown because the `dict_faceplates` variable (presumably, a dictionary) is missing the key `'FACEPLATES_ADE_00'`. I couldn't really tell you why that is, but that's the root of your problem. Check for anything overwriting the `dict_faceplates` variable elsewhere in the script.

---

<div class="post-metadata">

**Author:** ![jciatti](https://avatars.discourse-cdn.com/v4/letter/j/3da27b/32.png) [@jciatti](https://forum.inductiveautomation.com/u/jciatti)\
**Post date:** [November 1, 2018, 9:08pm UTC](https://forum.inductiveautomation.com/t/keyerror-in-script/20494/3 "2018-11-01T21:08:01Z")

</div>

HI Paul,

I’m seeing, in order, the follwoing writes to dict\_faceplates  
dict\_faceplates = {} # Dictonary to hold Faceplate Associations  
dict\_faceplates[tag.name] = system.dataset.toPyDataSet( system.tag.read(tag.fullPath).value )

There’s not much to go on with that, but I assume this script is being called once on the startup of the entire system, and I haven’t initiated that yet. I’ll start on that initialization route and see what happens. Thanks for the quick response.

---

<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:** [November 1, 2018, 9:15pm UTC](https://forum.inductiveautomation.com/t/keyerror-in-script/20494/4 "2018-11-01T21:15:27Z")

</div>

It’s either the initialization (likely) or `tag.name` isn’t exactly the literal string `'FACEPLATES_ADE_00'`.

---

<div class="post-metadata">

**Author:** ![WillMT10](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@WillMT10](https://forum.inductiveautomation.com/u/WillMT10)\
**Post date:** [November 1, 2018, 9:17pm UTC](https://forum.inductiveautomation.com/t/keyerror-in-script/20494/5 "2018-11-01T21:17:18Z")

</div>

PGriffith beat me to it but I’ll keep this here anyways. Have you tried just looping through the dictionary keys and printing them to the console to make sure the key you are looking for is actually in there and exactly how you have it typed (lowercase vs uppercase, etc)?

---

<div class="post-metadata">

**Author:** ![jciatti](https://avatars.discourse-cdn.com/v4/letter/j/3da27b/32.png) [@jciatti](https://forum.inductiveautomation.com/u/jciatti)\
**Post date:** [November 1, 2018, 9:39pm UTC](https://forum.inductiveautomation.com/t/keyerror-in-script/20494/6 "2018-11-01T21:39:42Z")

</div>

Yeah, i was able to print those to console. It found the exact tagname, but I’ll take another look tomorrow. Since it is actively running on a SCADA system right now, I am willing to bet the code it fine, it’s probably just how I imported everything piecemeal and didn’t just restore the gateway as a whole.
