Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
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.
Solved! Go to Solution.
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
use JSON.parse() method to parse the values before passing it to query
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