# Perspective Button to write to Database INDENT errors?

**URL:** <https://forum.inductiveautomation.com/t/perspective-button-to-write-to-database-indent-errors/28447>\
**Category:** Ignition\
**Created:** [September 20, 2019, 9:08pm UTC](https://forum.inductiveautomation.com/t/perspective-button-to-write-to-database-indent-errors/28447 "2019-09-20T21:08:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [September 20, 2019, 9:08pm UTC](https://forum.inductiveautomation.com/t/perspective-button-to-write-to-database-indent-errors/28447/1 "2019-09-20T21:08:56Z")

</div>

Trying to setup a button to write to a MySQL database.

Though the post don’t show it the first line “def” is the only one that is not tabbed.

```auto
def runAction(self, event):
	"""
	Method that will run whenever the selected event fires.

	Arguments:
		self: A reference to the component that is invoking this function.
		event: An object that holds information about the selected event type
	"""
	DateV = system.date.now()
	idV = 1
	query = "UPDATE table SET date = ? WHERE id = ?"
	args = [DateV, idV]
     system.db.runPrepUpdate(query, args)

```

I then get:

Unable to run function “runAction(self, event)”, code could not be compiled.

org.python.core.PySyntaxError: SyntaxError: (“mismatched input ‘’ expecting INDENT”, (’’, 1, 27, ‘def runAction(self, event):\n’))

---

<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:** [September 20, 2019, 9:14pm UTC](https://forum.inductiveautomation.com/t/perspective-button-to-write-to-database-indent-errors/28447/2 "2019-09-20T21:14:31Z")

</div>

Tab all of your actual code in by one tab.  
Extension functions, such as `runAction`, act as if you were defining a Python function - so the top line (`def runAction`) is the only line that should actually be at the minimum indent level. Your code should look like this:

```auto
def runAction(self, event):
"""
some docstring here
"""
	DateV = system.date.now()
	# the rest of your code

```

and **not** like this:

```auto
def runAction(self, event):
"""
some docstring here
"""
DateV = system.date.now()
# the rest of your code

```

---

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [September 20, 2019, 9:17pm UTC](https://forum.inductiveautomation.com/t/perspective-button-to-write-to-database-indent-errors/28447/3 "2019-09-20T21:17:14Z")

</div>

It is, how do you comment code on the forum so it keeps the tabs etc?

Thanks.

---

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [September 20, 2019, 9:34pm UTC](https://forum.inductiveautomation.com/t/perspective-button-to-write-to-database-indent-errors/28447/4 "2019-09-20T21:34:26Z")

</div>

I’m using the onActionPerformed but I had looked at the onClick mouse event at some point. 🙂 Only the default def runAction code was in it.

Would still like to know how to comment code in a post.

---

<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:** [September 20, 2019, 9:37pm UTC](https://forum.inductiveautomation.com/t/perspective-button-to-write-to-database-indent-errors/28447/5 "2019-09-20T21:37:53Z")

</div>

Put three backticks ``` before and after the code, on their own lines:

````auto
    ```
    code
    ```

````

(Or just use this icon: ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/3/314697fd3e850b915cc5586d2f589c85b2a9c1b7.png) )

---

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [September 20, 2019, 9:44pm UTC](https://forum.inductiveautomation.com/t/perspective-button-to-write-to-database-indent-errors/28447/6 "2019-09-20T21:44:23Z")

</div>

Ok, thanks for the help.
