# Perspective script syntax to check null value on dropdown component value

**URL:** <https://forum.inductiveautomation.com/t/perspective-script-syntax-to-check-null-value-on-dropdown-component-value/30749>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 17, 2019, 1:24am UTC](https://forum.inductiveautomation.com/t/perspective-script-syntax-to-check-null-value-on-dropdown-component-value/30749 "2019-12-17T01:24:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![guganathan.r](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@guganathan.r](https://forum.inductiveautomation.com/u/guganathan.r)\
**Post date:** [December 17, 2019, 1:24am UTC](https://forum.inductiveautomation.com/t/perspective-script-syntax-to-check-null-value-on-dropdown-component-value/30749/1 "2019-12-17T01:24:29Z")

</div>

I’m just writing a simple ‘if’ loop to check the content of dropdown value and popup a message to user if the content is empty when they press submit button. Since the dropdown menu has clear button on it, when we clear the button the dropdown value becomes null.  
I need syntax to check the null value in this dropdown component.

I used following syntax but getting error message.

if self.getSibling(“Dropdown”).props.value == “”:

if self.getSibling(“Dropdown”).props.value == “null”:

if self.getSibling(“Dropdown”).props.value == null:

Please correct me where I’m wrong. Thanks.

---

<div class="post-metadata">

**Author:** ![deon.korb](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@deon.korb](https://forum.inductiveautomation.com/u/deon.korb)\
**Post date:** [December 17, 2019, 4:47am UTC](https://forum.inductiveautomation.com/t/perspective-script-syntax-to-check-null-value-on-dropdown-component-value/30749/2 "2019-12-17T04:47:48Z")

</div>

Hi,

Try:

self.getSibling(“Dropdown”).props.value == None:

Regards,  
Deon

---

<div class="post-metadata">

**Author:** ![guganathan.r](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@guganathan.r](https://forum.inductiveautomation.com/u/guganathan.r)\
**Post date:** [December 17, 2019, 5:15am UTC](https://forum.inductiveautomation.com/t/perspective-script-syntax-to-check-null-value-on-dropdown-component-value/30749/3 "2019-12-17T05:15:42Z")

</div>

Dear Deon,  
Thanks for prompt response.  
Provided syntax works well when the dropdown.props.value is null (that is whenever I select one value in dropdown and clear the content, dropdown.props.value is null and syntax works).  
But during the session starup or view switchover, the dropdown.props.value is blank, hence the above syntax didnt solve my problem completely.  
However I created a custom value as selected label and used the syntax you provided, it works well and solved my issue.  
For custom selectedlabel I followed this recommendation:

> [@Getting the selected label of a dropdown](http://forum.inductiveautomation.com/t/getting-the-selected-label-of-a-dropdown/21956/3):
>
> To expand on Sam’s answer, especially if you don’t use integers as your option values: Create a custom property on the dropdown component with the key ‘selectedLabel’. Create a Property binding for selectedLabel, linked to this.props.value. Add a Script transform with the following code: x = None for i in range(len(self.props.options)): if self.props.options[i].value == value: x = self.props.options[i].label break return x As Sam mentioned, you can then reference self.getSibling('drRea…

Syntax I used as:  
self.getSibling("Dropdown").custom.selectedlabel == None:

Thanks.

---

<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:** [December 17, 2019, 4:22pm UTC](https://forum.inductiveautomation.com/t/perspective-script-syntax-to-check-null-value-on-dropdown-component-value/30749/4 "2019-12-17T16:22:34Z")

</div>

`if self.getSibling(“Dropdown”).props.value:`

Should probably work. Python’s singleton for null, `None`, is evaluated as `False`, as is an empty string `""`, so a simple if statement will only pass if there is at least one character in the string.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 17, 2019, 4:31pm UTC](https://forum.inductiveautomation.com/t/perspective-script-syntax-to-check-null-value-on-dropdown-component-value/30749/5 "2019-12-17T16:31:10Z")

</div>

The following code will work to determine if your Dropdown has no current selection:

```auto
(self.props.value is None) or (len(self.props.value) == 0)

```

Scripting uses Jython, which uses Python’s `None` instead of Java’s `null`.

From your listed attempts:

```auto
if self.getSibling("Dropdown").props.value == null:
    # this will NEVER work in Ignition because it will treat null as a variable

if self.getSibling("Dropdown").props.value == "null":
    # this will only ever work if you supply a String with a value of "null"

if self.getSibling("Dropdown").props.value == "":
    # this will work if no option is selected, unless you use the "clear" option, at which point you need the None option I supplied you.

```

---

<div class="post-metadata">

**Author:** ![guganathan.r](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@guganathan.r](https://forum.inductiveautomation.com/u/guganathan.r)\
**Post date:** [December 19, 2019, 7:29am UTC](https://forum.inductiveautomation.com/t/perspective-script-syntax-to-check-null-value-on-dropdown-component-value/30749/6 "2019-12-19T07:29:40Z")

</div>

Works well. Thanks for your responses.
