90
Views
8
Comments
Solved
How to send the output of a sql table while exposing a REST API in outsystems?

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?




2025-02-04 10-17-42
Shreelakshmi N S
Champion
Solution

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


SQLOutputMapping.oml
2025-02-04 10-17-42
Shreelakshmi N S
Champion

Hi, 

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!

Regards,

Shree

UserImage.jpg
SS27

Hi,

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.

2018-10-29 08-31-03
João Marques
 
MVP

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

UserImage.jpg
SS27

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 

2018-10-29 08-31-03
João Marques
 
MVP

Hi SS27,


Have you debugged it to see if the query is returning any value?

UserImage.jpg
SS27

Hi
As i mentioned in the question also My sql query is working fine as when I test it with sample values it returns correct rows 

2025-02-04 10-17-42
Shreelakshmi N S
Champion
Solution

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


SQLOutputMapping.oml
2022-07-12 01-10-14
Jithu Cheriath Thomas

Hi, 

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.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.