cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

How to pass List of values from json object to SQL Query Service

snoor
7-Bedrock

How to pass List of values from json object to SQL Query Service

I need to call a SQL Query service. Which Look-Likes :

select * from public.styleassociation where id in (?); 

As input I am passing Json Object (Ex:  {  "values" :  [1,2,3]}

Can anyone help me, how to extract the values in "?" place.

1 ACCEPTED SOLUTION

Accepted Solutions
snoor
7-Bedrock
(To:slangley)

Hello @slangley ,

 

I have found answers my self, the solution is 

we need to iterate the List of values  and append each value as a single string with the single quotes and comas (EX: ‘ID1’,’ID2’). The same string we need to pass as a SQL service parameter and it working fine.

The same approached I have tried with the NUMBER parameter and its working.

 

Ex Code :

var res = "";

for(var i=0; i<tagsArr.length;i++){
var res1 = "\'" + tagsArr[i] + "\'" + ",";
res += res1;
}

var tagsVal = res.substr(0, res.length-1); 

 

And in query param you need to pass  where tag_id IN (<<tagsVal>>) not in [[tagsVal]]

 

Best Regards,

Noor

View solution in original post

3 REPLIES 3
rosharma
16-Pearl
(To:snoor)

use JSON.parse() method to parse the values before passing it to query

slangley
23-Emerald II
(To:rosharma)

Hi @snoor.

 

If the solution provided by @rosharma answered your question, please mark it as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon

snoor
7-Bedrock
(To:slangley)

Hello @slangley ,

 

I have found answers my self, the solution is 

we need to iterate the List of values  and append each value as a single string with the single quotes and comas (EX: ‘ID1’,’ID2’). The same string we need to pass as a SQL service parameter and it working fine.

The same approached I have tried with the NUMBER parameter and its working.

 

Ex Code :

var res = "";

for(var i=0; i<tagsArr.length;i++){
var res1 = "\'" + tagsArr[i] + "\'" + ",";
res += res1;
}

var tagsVal = res.substr(0, res.length-1); 

 

And in query param you need to pass  where tag_id IN (<<tagsVal>>) not in [[tagsVal]]

 

Best Regards,

Noor

Top Tags