Hi all i am trying to expose a rest API in outsystems in which i need to output the columns produced by a sql query , assume the output of sql query looks like this:-
Now I created an entity in database of same type as the sql query output, assume it looks like this:-
Then i created an output parameter in the API method of the same data type as my entity 'Output'
I assigned the values like this:-
Output.Current.City= SQL.List.Current.OutputStructure.City
Output.Current.City= SQL.List.Current.OutputStructure.Val1
Output.Current.City= SQL.List.Current.OutputStructure.Val2
Where OutputStructure is a structure i made to hold the sql output.
This is my API method with the assign statements having the above 3 kind of statements, My sql query is working fine as when I test it with sample values it returns correct rows
But in this approach i am not getting any data in my json output. I am taking input parameter as URL. How can i proceed with this?
Hi,
After assigning you need to map the values also like below. Please find the OML also attached for your reference. I have added the logic in data action.
Hope this helps!!
Regards,
Shree
Is there any reason for assigning values individually?
Instead of assigning each values in the assign, directly assign like below,
Output = SQL.List.Current.OutputStructure
Let me know if this works!
No this doesn't work as i am still getting {} in my output I even tried changing the data type of my output parameter to sql record for this but it didn't work.
Hi SS27,
Your output seems to be a List, that's why you have the current in your assigns as Output.Current.City.
In this case, you're not adding no value to the list, hence your list is empty.
I would suggest doing an assign Output = SQL.List.
When doing that, you will see below the mapping of the Output attributes to the query attributes. You then should do the mapping between both structures.
Kind Regards,João
Hi João , i tried this i am still not getting any output in my API , can you help me with the general way of assigning the output of SQL to my output parameter, Thanks
Have you debugged it to see if the query is returning any value?
HiAs i mentioned in the question also My sql query is working fine as when I test it with sample values it returns correct rows
I hope you got the solution, if not please try the below mentioned way:
1) Try List append all.
2) if that is not returning the proper output , you perform deserializing and serializing options too.