# Global name 'status\_red' is not defined

**URL:** <https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999>\
**Category:** Ignition\
**Tags:** scripting, ignition80\
**Created:** [November 26, 2020, 9:18pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999 "2020-11-26T21:18:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 26, 2020, 9:18pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/1 "2020-11-26T21:18:33Z")

</div>

So I have project script and a style in the Styles in the project. When I try to use the style I get the global name ‘status\_red’ is not defined error. I used the path from the project, is there something special I must do to reference these?Thx, jake

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 27, 2020, 2:26am UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/2 "2020-11-27T02:26:39Z")

</div>

> [@codersmurf](#):
>
> When I try to use the style I get the global name ‘status\_red’ is not defined error.

How are you 'trying to use' it? Screenshots would be helpful.

What is the project script doing and how does it relate to using Perspective Styles? All you need to do to use a Style is to copy the path to it into a component's style.classes (there could be many of these at different levels in a component's prop depending on component but applying the style in the props.style.classes will apply for the \*whole component) value. If course you can assign this dynamically via a binding or a script, but essentially they will just be writing the style path or paths into this

As a side note, consider creating 'status' as a folder in the styles, as in sure once you start using styles that you'll end up with many of them

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 27, 2020, 3:23am UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/3 "2020-11-27T03:23:14Z")

</div>

![ignition1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/3/a3005fbbcf2a1ce0515742bb78f034774ff54040.jpeg)

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 27, 2020, 3:25am UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/4 "2020-11-27T03:25:47Z")

</div>

There’s the script, it’s global to the project. Pretty much the only thing I use the styles for is bg color, so it didn’t seem useful to add a folder for them.Thx, jake

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 27, 2020, 12:21pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/5 "2020-11-27T12:21:20Z")

</div>

In the script, you’re trying to return variables called eg `status_white` which you haven’t defined within your function. What the style classes property is expecting is a string with the style path in it. You need to return a string, e.g.  
`return 'status_white'`

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 27, 2020, 2:33pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/6 "2020-11-27T14:33:40Z")

</div>

Ah, so in script if you set the style to a string it will look for the style in the project, I’ll try this now.Thx, jake

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 27, 2020, 8:53pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/7 "2020-11-27T20:53:38Z")

</div>

What calls the script? I assumed that it was somehow writing its return value into a style.classes property

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 27, 2020, 9:55pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/8 "2020-11-27T21:55:53Z")

</div>

[view.json](https://forum.inductiveautomation.com/uploads/short-url/y0ZmKBBz5mjLHgkuu4GR3uIoix3.json) (10.7 KB)

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 27, 2020, 9:57pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/9 "2020-11-27T21:57:33Z")

</div>

![ignition2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/8/b8ba62c8ae84aa2f43bbd34e82fb6ec0a1bf5810.jpeg)

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 27, 2020, 10:23pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/10 "2020-11-27T22:23:11Z")

</div>

A button calls onClick the Load(self) function, it passes itself so the session comes across.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 27, 2020, 10:46pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/11 "2020-11-27T22:46:08Z")

</div>

You’re calling the script, but the return value is lost as you’re not assigning it to anything.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/e/1e15c51b23be454ddc06570cb7f1596d5b94f791.png)

You should be assigning it to the style.classes property of whatever it is that you want to set the style for. E.g.  
`self.getSibling("Label").props.style.classes = Units.Load(self)`

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 27, 2020, 10:48pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/12 "2020-11-27T22:48:45Z")

</div>

the GetColor function is called by the load script to get the color for the line, then that style is applied to each cell as the table is filled in. The load doesn’t return anything as it’s filling in the table directly.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 27, 2020, 10:49pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/13 "2020-11-27T22:49:17Z")

</div>

~~Also, it’d be far more efficient to scrap the script and instead do all of this in an expression binding. The blocking tag reads are going to kill your performance~~

Ignore that, I posted at the same time you did.

I probably need to see your full Units script

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 27, 2020, 10:53pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/14 "2020-11-27T22:53:48Z")

</div>

So I’m not sure I can do that. The status along with the statusnormal tags determine the color, the other stuff I suppose could do bindings. This script was carried over from vision on 7.8.5, and it wan’t fast, but did everything I needed. I’m trying not to run through through the table twice, also, tags can disappear and reappear. And which tags fill in the table is determined by the login.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 27, 2020, 10:55pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/15 "2020-11-27T22:55:52Z")

</div>

> [@nminchin](#):
>
> I probably need to see your full Units script

Not sure if you saw this as i edited after you replied

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 27, 2020, 10:57pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/16 "2020-11-27T22:57:05Z")

</div>

Oh, it’s in another post with other script problems.

[other post](http://forum.inductiveautomation.com/t/perspective-table-what-is-props-data-cause-scripts-dont-think-its-a-dataset/41018/5)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 27, 2020, 11:00pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/17 "2020-11-27T23:00:42Z")

</div>

Are you able to edit it and paste back your code inside of three back-ticks (```). This will keep the formatting intact. Or copy in your code, select it, and press the preformatted button ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/1/3186ff843c989460145b4e7ab0429f4a8f69b369.png)

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 27, 2020, 11:01pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/18 "2020-11-27T23:01:24Z")

</div>

oh, ticks, thought it was 3 dots, here you go:

‘’’  
import time  
def GetColor(unit):  
d = system.tag.readBlocking([’[default]’ + unit + ‘.enabled’])[0].value  
if d == False:  
return ‘status\_darker\_blue’  
s = system.tag.readBlocking([’[default]’ + unit + ‘/Status’])[0]  
if s.quality.isGood() == False:  
return ‘status\_light\_grey’  
else:  
fp = ‘[default]’ + unit + ‘/Faulted’  
if False:  
#if system.tag.exists(fp) == True:  
f = system.tag.readBlocking(fp)[0]  
if f.value == True:  
color = ‘status\_light\_grey’  
else:  
color = ‘status\_white’  
else:  
sn = system.tag.readBlocking([’[default]’ + unit + ‘/StatusNormal’])[0]  
norms = sn.value.split(’,’)  
color = ‘status\_red’  
for norm in norms:  
if s.value == int(norm):  
color = ‘status\_white’  
break  
return color

def Load(caller):  
units\_tag = caller.session.props.auth.user.userName  
hide\_customer = False;  
if units\_tag == ‘TOPSDemo’:  
hide\_customer = True

```
units = system.tag.readBlocking(['[default]' + units_tag + '/Units'])[0].value.split(',')

unitList = caller.getSibling("Units")
#ds = system.dataset.clearDataset(unitList.props.data)
ds = []

for unit in units:
	#system.gui.messageBox(unit)
	color = GetColor(unit)
	company = ""
	location = ""
	volts = ""
	d = system.tag.readBlocking(['[default]' + unit + '.enabled'])[0].value
	if d == False:
		comploc = system.tag.readBlocking(['[default]Disabled-' + unit])[0].value.split(',')
		company = comploc[0]
		location = comploc[1]
		volts = "NA"
	else:
		if hide_customer == True:
			company = 'NA'
			location = 'NA'
		else:
			company = system.tag.readBlocking(['[default]' + unit + '/Company'])[0].value
			location = system.tag.readBlocking(['[default]' + unit + '/Location'])[0].value
		compv = system.tag.readBlocking(['[default]' + unit + '/CompMainsVoltage'])[0]
		if compv and compv.quality.isGood() == True:
			volts = "%4.1f" % compv.value
		else:
			volts = "NA"
	data = [{"value": unit, "style": color}
			,{"value": company, "style": color}
			,{"value": location, "style": color}
			,{"value": volts, "style": color}]
	ds.append(data)

unitList.props.data = ds

```

‘’’

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 27, 2020, 11:01pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/19 "2020-11-27T23:01:51Z")

</div>

```auto
import time
def GetColor(unit):
	d = system.tag.readBlocking(['[default]' + unit + '.enabled'])[0].value
	if d == False:
		return 'status_darker_blue'
	s = system.tag.readBlocking(['[default]' + unit + '/Status'])[0]
	if s.quality.isGood() == False:
		return 'status_light_grey'
	else:
		fp = '[default]' + unit + '/Faulted'
		if False:
		#if system.tag.exists(fp) == True:
			f = system.tag.readBlocking(fp)[0]
			if f.value == True:
				color = 'status_light_grey'
			else:
				color = 'status_white'
		else:
			sn = system.tag.readBlocking(['[default]' + unit + '/StatusNormal'])[0]
			norms = sn.value.split(',')
			color = 'status_red'
			for norm in norms:
				if s.value == int(norm):
					color = 'status_white'
					break
	return color

def Load(caller):
	units_tag = caller.session.props.auth.user.userName
	hide_customer = False;
	if units_tag == 'TOPSDemo':
		hide_customer = True
	
	units = system.tag.readBlocking(['[default]' + units_tag + '/Units'])[0].value.split(',')
	
	unitList = caller.getSibling("Units")
	#ds = system.dataset.clearDataset(unitList.props.data)
	ds = []

	for unit in units:
		#system.gui.messageBox(unit)
		color = GetColor(unit)
		company = ""
		location = ""
		volts = ""
		d = system.tag.readBlocking(['[default]' + unit + '.enabled'])[0].value
		if d == False:
			comploc = system.tag.readBlocking(['[default]Disabled-' + unit])[0].value.split(',')
			company = comploc[0]
			location = comploc[1]
			volts = "NA"
		else:
			if hide_customer == True:
				company = 'NA'
				location = 'NA'
			else:
				company = system.tag.readBlocking(['[default]' + unit + '/Company'])[0].value
				location = system.tag.readBlocking(['[default]' + unit + '/Location'])[0].value
			compv = system.tag.readBlocking(['[default]' + unit + '/CompMainsVoltage'])[0]
			if compv and compv.quality.isGood() == True:
				volts = "%4.1f" % compv.value
			else:
				volts = "NA"
		data = [{"value": unit, "style": color}
				,{"value": company, "style": color}
				,{"value": location, "style": color}
				,{"value": volts, "style": color}]
		ds.append(data)

	unitList.props.data = ds

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 27, 2020, 11:02pm UTC](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999/20 "2020-11-27T23:02:16Z")

</div>

I think you used apostrophes. Back ticks are the character on the tilde (~) button

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/1/91676947132fe199806a04b640bc0ccf760de8a4.png)  
the bottom character

[Next page](https://forum.inductiveautomation.com/t/global-name-status-red-is-not-defined/40999.md?page=2)
