Insert row using button

Hello Friends,

I’m trying to insert a new row using the button. When I’m passing all values then inserted a new row properly but I’m not passing any value then the below error occurs.

java.lang.NullPointerException
java.lang.NullPointerException: java.lang.NullPointerException

When I’m not passing any value then automatically added NULL value for the particular column. Please can you suggest to me how it is possible?
I’m using the below code for the inserted a new row.

name = event.source.parent.getComponent(‘Name’).text
details =event.source.parent.getComponent(Details).text
date = event.source.parent.getComponent(‘date’).date

table = event.source.parent.getComponent(‘Table’)

insertQuery = ‘INSERT INTO Sample (name, details, date) VALUES(?,?,?)’
args = [name, details, system.date.format(date, “yyyy-MM-dd HH:mm:ss”)]

system.db.runPrepUpdate(insertQuery, args)
system.db.refresh(table, “Data”)

Thanks,
Priyanka

What line is the nullpointer pointing too? im guessing the date or args?

Hi @victordcq,

Thank you for your reply. args line generates the NullPointerException.

alright add in

if date == None:
		date = system.date.now()

somewhere between date and args

or if you wat it to be None

if date == None:
 args = [name, details, None]
else : 
 args = [name, details, system.date.format(date, “yyyy-MM-dd HH:mm:ss”)]
1 Like

@victordcq Thank you so much for your help. Solved my problem.

1 Like

np^^