# Data Input to Database or Custom Session Prop on Button Press Not Working

**URL:** <https://forum.inductiveautomation.com/t/data-input-to-database-or-custom-session-prop-on-button-press-not-working/85755>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [February 15, 2024, 2:38pm UTC](https://forum.inductiveautomation.com/t/data-input-to-database-or-custom-session-prop-on-button-press-not-working/85755 "2024-02-15T14:38:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gillian\_Carter](https://avatars.discourse-cdn.com/v4/letter/g/8edcca/32.png) [@Gillian\_Carter](https://forum.inductiveautomation.com/u/Gillian_Carter)\
**Post date:** [February 15, 2024, 2:38pm UTC](https://forum.inductiveautomation.com/t/data-input-to-database-or-custom-session-prop-on-button-press-not-working/85755/1 "2024-02-15T14:38:12Z")

</div>

I have a page where users will input information from dropdowns, I am trying to either set that information to a custom session prop and/or insert the input information into an sql database on a button press using the event configuration. I have used similar codes for different purposes but when I click the button after launching perspective neither option is working.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/d/6d0c69dcc0ca2b1aed052ca6b46a5b9f724d26d9.png)

```auto
def runAction(self, event):
	date_time = self.getSibling("DateTimeInput").props.value
	work_order = self.getSibling("Dropdown_WorkOrder").props.value
	machine_status = self.getSibling("Dropdown_MachineStatus").props.value
	status_reason = self.getSibling("Dropdown_StatusReason").props.value
	planned_workplace = concat(self.getSibling("Dropdown_Location").props.value, self.getSibling("TextField_Machine").props.text)
	
	session.custom.date_time = date_time
	session.custom.work_order = work_order
	session.custom.machine_status = machine_status
	session.custom.status_reason = status_reason
	session.custom.planned_workplace = planned_workplace

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/3/a345876e9fe19132feb6fa936feb7ecf3ab97d5f.png)

```auto
	# Create a python dictionary of parameters to pass
	parameters = {"date_time":self.getSibling("DateTimeInput").props.value, 
					"work_order":self.getSibling("Dropdown_WorkOrder").props.value,
					"machine_status":self.getSibling("Dropdown_MachineStatus").props.value,
					"status_reason":self.getSibling("Dropdown_StatusReason").props.value,
					"planned_workplace":concat(self.getSibling("Dropdown_Location").props.value, self.getSibling("TextField_Machine").props.text)}
	
	# Run the Named Query
	system.db.runNamedQuery("Insert Status Data", parameters)

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 15, 2024, 3:17pm UTC](https://forum.inductiveautomation.com/t/data-input-to-database-or-custom-session-prop-on-button-press-not-working/85755/2 "2024-02-15T15:17:30Z")

</div>

I'm not a Python expert but as far as I know `concat()` is for merging arrays. You just need the `+` operator:  
`planned_workplace = self.getSibling("Dropdown_Location").props.value + self.getSibling("TextField_Machine").props.text`

Regarding the SQL query, have you set the default database in the project settings?

I note than you have two events on the one button, onClick and onActionPerformed.

You should run both session props update and SQL query on the onActionPerformed event for a couple of reasons.

- onClick will execute even if the button is disabled. It may not bother you in this application but will catch you out sometime if you develop a bad habit.
- onActionPerformed doesn't execute if the button is disabled. If I remember correctly, it will also work with keyboard action.

There should be errors in the gateway logs at Status | Diagnostics | Logs.

---

<div class="post-metadata">

**Author:** ![Gillian\_Carter](https://avatars.discourse-cdn.com/v4/letter/g/8edcca/32.png) [@Gillian\_Carter](https://forum.inductiveautomation.com/u/Gillian_Carter)\
**Post date:** [February 20, 2024, 3:03pm UTC](https://forum.inductiveautomation.com/t/data-input-to-database-or-custom-session-prop-on-button-press-not-working/85755/3 "2024-02-20T15:03:09Z")

</div>

I was testing if either onClick or onActionPerformed would work, and neither of them work

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 20, 2024, 3:34pm UTC](https://forum.inductiveautomation.com/t/data-input-to-database-or-custom-session-prop-on-button-press-not-working/85755/4 "2024-02-20T15:34:18Z")

</div>

> [@Gillian\_Carter](#):
>
> ... and neither of them work.

You're not really giving us anything to go on. Give us information on:

- What were you expecting?
- What did you get?
- What errors were generated? (Did you check on the gateway | Status | Diagnostics | Logs?)

> **[Gateway Loggers | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/tutorials/tutorials-and-helpful-tricks/gateway-loggers)**
>
> Tips for examining the Gateway's loggers

> **[system.util.getLogger | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-util/system-util-getLogger)**
>
> Returns a Logger object that can be used to log messages to the console.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 20, 2024, 4:01pm UTC](https://forum.inductiveautomation.com/t/data-input-to-database-or-custom-session-prop-on-button-press-not-working/85755/5 "2024-02-20T16:01:29Z")

</div>

onActionPerformed is the correct event.

I'm not sure what you mean by "neither of them work". I assume that means you didn't see the data show up in the database as expected.

Generally this means that something is happening that you're not expecting, most likely an error. I would expect you to get a pop up with an error message.

Now, on to what I think the issue actually is here, which @transistor hinted at earlier.

> [@Transistor](#):
>
> I'm not a Python expert but as far as I know `concat()` is for merging arrays

`concat()` isn't a built-in function, and I don't see any imports. I strongly susspect that you're getting an error, something like:

```auto
Error running action 'component.onActionPerformed' on Main Views/Trending/customTrend@D/root/Button: Traceback (most recent call last): File "<function:runAction>", line 2, in runAction NameError: global name 'concat' is not defined

```

and that script execution is never arriving at the second parts of your script.

You really just need the `+` operator to concatenate two strings.

I think probably what happened is you've mixed the _Expression Language_ `concat()` expression with a jython script.

---

<div class="post-metadata">

**Author:** ![Gillian\_Carter](https://avatars.discourse-cdn.com/v4/letter/g/8edcca/32.png) [@Gillian\_Carter](https://forum.inductiveautomation.com/u/Gillian_Carter)\
**Post date:** [February 20, 2024, 4:45pm UTC](https://forum.inductiveautomation.com/t/data-input-to-database-or-custom-session-prop-on-button-press-not-working/85755/6 "2024-02-20T16:45:06Z")

</div>

I would like for when the button is clicked for the information from the drop downs to be saved in a way that can be used in other views, I would prefer for it to be saved into the database, but also tried just setting them to a custom session prop.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/5/65ef7bdfecb81bd3bfde831a93e30d919b9c5ac9.png)  
I get this error popping up saying NoneType object has no attribute props, but I have a value selected for each dropdown  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/c/5c6f001fae44b912a3abc265c109a6e69ba7a8d3.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/6/96dea911ce9e03b52e86fac53e1e69f3a792dea5.png)  
I did test the INSERT Named Query so it should work, it seems to be the button event code  
I made the change to + and there is still an issue

```auto
def runAction(self, event):
	# Create a python dictionary of parameters to pass
	parameters = {"date_time":self.getSibling("DateTimeInput").props.value, 
				"work_order":self.getSibling("Dropdown_WorkOrder").props.value,
				"machine_status":self.getSibling("Dropdown_MachineStatus").props.value,
				"status_reason":self.getSibling("Dropdown_StatusReason").props.value,
				"planned_workplace":self.getSibling("Dropdown_Location").props.value + self.getSibling("TextField_Machine").props.text}
	
	# Run the Named Query
	system.db.runNamedQuery("Insert Status Data", parameters)"

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 20, 2024, 4:49pm UTC](https://forum.inductiveautomation.com/t/data-input-to-database-or-custom-session-prop-on-button-press-not-working/85755/7 "2024-02-20T16:49:19Z")

</div>

Something is wrong with the name of the `DateTimeInput`. That error means that the `self.getSibling()` function is not finding the supplied component name. Usually that means that the spelling doesn't match. From looking at it, everything appears to be correct.

Make sure you haven't accidentally added a space to the end of the name.

---

<div class="post-metadata">

**Author:** ![Gillian\_Carter](https://avatars.discourse-cdn.com/v4/letter/g/8edcca/32.png) [@Gillian\_Carter](https://forum.inductiveautomation.com/u/Gillian_Carter)\
**Post date:** [February 20, 2024, 5:24pm UTC](https://forum.inductiveautomation.com/t/data-input-to-database-or-custom-session-prop-on-button-press-not-working/85755/8 "2024-02-20T17:24:18Z")

</div>

Thank you, it was a silly mistake in the end. I had switch the textfield to a drop down but hadn't updated that in the event configuration code

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 20, 2024, 5:55pm UTC](https://forum.inductiveautomation.com/t/data-input-to-database-or-custom-session-prop-on-button-press-not-working/85755/9 "2024-02-20T17:55:19Z")

</div>

You can avoid some of the getSibling coding - which tends to make your application "brittle" when you make changes - by binding your form elements to view custom properties. Then reference those in your scripts. You are then free to move and rename the components without breaking the relationships.

If you do this then form validation becomes much simpler too. You can have another custom property which gives a true if all the fields are OK. This in turn can be used to enable / disable the "Save" button, or whatever.
