Perumss
Perumss

Reputation: 137

IBM Worklight - How to construct a JSON object in SQL adapter

To construct a JSON object in a SQL adapter I have tried the following:

{
    'PatientID':4, 
    'FName':'test',
    'LName':'test',
    'AGE':1,
    'DOB':1988-09-01,
    'GENDER':'m',
    'BG':'A+'
}

However I get an error:

{
   "errors": [
      "Runtime: Method createSQLStatement was called inside a JavaScript function."
   ],
   "info": [
   ],
   "isSuccessful": false,
   "warnings": [
   ]
}


Full size image
how to construct Json oblect in sql Adapter in IBM Worklight

Upvotes: 0

Views: 485

Answers (2)

Anton
Anton

Reputation: 3166

createSQLStatement API should not be used inside of your functions. You it outside of functions, just like tutorial shows (slide 10) http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v600/04_03_SQL_adapter_-_Communicating_with_SQL_database.pdf

Upvotes: 0

jnortey
jnortey

Reputation: 1625

First, in the "Invoke Procedure Data" window for your adapter, don't wrap the object in quotes. If you do, it will think that the entire thing is a string.

If you remove the beginning and ending quotes then you almost have it correct. The window will take valid JSON objects, but only if all non integers are strings. Since 1988-09-01 is not a valid integer, it must be wrapped in quotes. You should be able to copy/paste this object into the wizard:

{
    'PatientID':4, 
    'FName':'test',
    'LName':'test',
    'AGE':1,
    'DOB':"1988-09-01",
    'GENDER':'m',
    'BG':'A+' 
}

Upvotes: 2

Related Questions