# Perspective - prevent "null" on text field when retrieving data from SQL

**URL:** <https://forum.inductiveautomation.com/t/perspective-prevent-null-on-text-field-when-retrieving-data-from-sql/84431>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 18, 2024, 9:18am UTC](https://forum.inductiveautomation.com/t/perspective-prevent-null-on-text-field-when-retrieving-data-from-sql/84431 "2024-01-18T09:18:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davee\_s](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@davee\_s](https://forum.inductiveautomation.com/u/davee_s)\
**Post date:** [January 18, 2024, 9:18am UTC](https://forum.inductiveautomation.com/t/perspective-prevent-null-on-text-field-when-retrieving-data-from-sql/84431/1 "2024-01-18T09:18:13Z")

</div>

Hello guys, on Perspective I have a popup view and on startup I get data from SQL through a NamedQuery (SELECT \*), and then populate input fields and text fields with data retrieved.  
The problem is that if a field in SQL is a varchar and its value is NULL (not populated) Perspective shows "null" in the text field.  
Is there a way to prevent this and set the text field = "" or have I to check in my script for every varchar to not be "null"?

This is the code to populate fields on the popup view on startup:

```auto
if (self.params.IDOrder != "") :
	dataOrder = system.db.runNamedQuery('Order/SelectByID', {'IDOrder': self.params.IDOrder})
	self.params.IDCoil = dataOrder[0]["IDCoil"]
	
	dataContainer1 = self.getChild("root").getChild("Flex container").getChild("Data container1")
	
	dataContainer1.getChild("FlexContainer_0").getChild("CutLength").props.value = dataOrder[0]["CutLength"]
	dataContainer1.getChild("FlexContainer_1").getChild("TrimWidth").props.value = dataOrder[0]["TrimWidth"]
	dataContainer1.getChild("FlexContainer_2").getChild("TargetSheets").props.value = dataOrder[0]["TargetSheets"]
	dataContainer1.getChild("FlexContainer_4").getChild("TargetPackages").props.value = dataOrder[0]["TargetPackages"]
	dataContainer1.getChild("FlexContainer_8").getChild("StrapType").props.value = dataOrder[0]["StrapType"]
	dataContainer1.getChild("FlexContainer_9").getChild("BeamType").props.value = dataOrder[0]["BeamType"]
	dataContainer1.getChild("FlexContainer_11").getChild("CornerType").props.value = dataOrder[0]["CornerType"]
	dataContainer1.getChild("FlexContainer_12").getChild("StrapNumber").props.value = dataOrder[0]["StrapNumber"]
	
	dataContainer2 = self.getChild("root").getChild("Flex container").getChild("Data container2")
	
	dataContainer2.getChild("FlexContainer_6").getChild("FlexContainer").getChild("LengthToleranceMin").props.value = dataOrder[0]["NegativeLengthTolerance"]
	dataContainer2.getChild("FlexContainer_6").getChild("FlexContainer").getChild("LengthToleranceMax").props.value = dataOrder[0]["PositiveLengthTolerance"]
	dataContainer2.getChild("FlexContainer_7").getChild("FlexContainer").getChild("WidthToleranceMin").props.value = dataOrder[0]["NegativeWidthTolerance"]
	dataContainer2.getChild("FlexContainer_7").getChild("FlexContainer").getChild("WidthToleranceMax").props.value = dataOrder[0]["PositiveWidthTolerance"]
	dataContainer2.getChild("FlexContainer_10").getChild("FlexContainer").getChild("ThicknessToleranceMin").props.value = dataOrder[0]["NegativeThicknessTolerance"]
	dataContainer2.getChild("FlexContainer_10").getChild("FlexContainer").getChild("ThicknessToleranceMax").props.value = dataOrder[0]["PositiveThicknessTolerance"]
	dataContainer2.getChild("FlexContainer_4").getChild("Customer").props.text = dataOrder[0]["Customer"]
	dataContainer2.getChild("FlexContainer_5").getChild("Batch").props.text = dataOrder[0]["Batch"]
	dataContainer2.getChild("FlexContainer").getChild("Info1").props.text = dataOrder[0]["Info1"]
	dataContainer2.getChild("FlexContainer_0").getChild("Info2").props.text = dataOrder[0]["Info2"]
	dataContainer2.getChild("FlexContainer_1").getChild("Info3").props.text = dataOrder[0]["Info3"]
	dataContainer2.getChild("FlexContainer_2").getChild("Info4").props.text = dataOrder[0]["Info4"]
	dataContainer2.getChild("FlexContainer_3").getChild("Info5").props.text = dataOrder[0]["Info5"]

```

 ![Screenshot 2024-01-18 101142](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/5/d59fcf932dd1751f71fc7ce442b905333367aac1.png)  
 ![Screenshot 2024-01-18 101208](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/1/310ce75f95443a49caa7368406552c8b7f267e95.png)  
 ![Screenshot 2024-01-18 101229](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/7/07e78c32a401bf05ae9cc7951ddf82b7d8f1995f.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 18, 2024, 9:54am UTC](https://forum.inductiveautomation.com/t/perspective-prevent-null-on-text-field-when-retrieving-data-from-sql/84431/2 "2024-01-18T09:54:06Z")

</div>

You could do it in the query:

```sql
select coalesce(some_field, '')

```

or in your init script:

```python
some_component.props.value = dataOrder[0]['field'] or ''

```

Side note that's only half relevant:  
I dislike init scripts. I'd rather use a custom property, put a query binding on it, configure its return type to json, then bind my fields on that property.  
init scripts make it harder to see where values come from.
