I am trying to execute a script that receives as input the state of a checkbox and the oid of a table in order to change a field in the data base. Note that the change is not made in the script but the output is needed in order to make the change ater the cript is done running.
Here is the code of the script:
#input String chkbox_entry
#input int oidBank
#output String chkbox_exit
def resultQuery = ""
def dbId = "db1"
def session = getDBSession(dbId)
//query to get the field i need
def query = session.createSQLQuery("SELECT DBNAME.DBTABLE.ES_TARJETA FROM DBNAME.DBTABLE WHERE DBNAME.DBTABLE.OID = :oidBanco")
resultQuery = query.uniqueResult()
//change the state accordingly and give it to chkbox_exit
if (chkbox_entry== "" && resultQuery =="S") //means that the current state is S but they want N
if (chkbox_entry== "" && resultQuery =="N")
if (chkbox_entry== "S")
return ["chkbox_exit": chkbox_exit]
Let me elaborate:
The state of the checkbox I receive as an input can be either S, N or "" (note that "" isnt null but empty). Why do I need the sql consult to retreive either S or N from the DB? That is exactly what I need to change. I am trying to update the state depending on what the user checks or doesnt check. If at first the DB shows N to the user and they uncheck it, I have to save it as S (Note that N and S correspond to No and Si in spanish).
Following debug, if the user decided to update the state from N to S (or viceversa), once the user hits Save and the data flows to the script, it enters to the script through the input String chkbox_entry as an String (0 elements) .
In order to "save" (remeber i do not save anything here, I only "make the change" needed and send it to the DB from here) the new state I need to know the current state of DBNAME.DBTABLE.ES_TARJETA, that result is stored in resultQuery.
That is why I made the sql consult to the DB so that if the user checks the item (assuming the current state was N and wanted to change it to S), as input besides the OidBank which i use to get the current state of DBNAME.DBTABLE.ES_TARJETA from the query in order to change that string somewhere else in the project but sending the result as output to mak said change. Checking RTXError and RTX log files i get the same error: Unable to execute the script java.lang.NullPointerException but i do not know what it meas and what to do.
If the user chooses not to change then it has to stay the same as it was (S or N respectively).