cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Justinrr07
Helper I
Helper I

Unable to Return Result Set from On-Premise SQL Server Stored Procedure

Can someone please help me understand why I'm not able to see a ResultSet from my Stored Procedure. I only return an Output.

Capture.JPGCapture2.JPG

1 ACCEPTED SOLUTION

Accepted Solutions

Ok, after extensive testing and trial and error, I got it working. I guess I had to change the name of the SQL step to "Execute a SQL Query" even though its a Stored Procedure task.

Capture.JPG

 

Add an expression to the response task in the Body field:

body('Execute_a_SQL_query').ResultSets.Table1

Capture2.JPG

and now it works fine. The only thin I was doing different in my previous attempts was the SQL task name was different. It still matched my Response expression but only once I changed it to "Execute a SQL Query" did it start working. Seems strange to me.

I'm also disappointed by the limitations of this method i.e. can't return data type image and I can't return a time converted to an integer. After 4 days of trial and error, I'll take what I can get.

View solution in original post

12 REPLIES 12
Pstork1
Dual Super User III
Dual Super User III

When you click on the "Click to Download" link in the output section what do you get?  is the screen blank or filled with JSON?  If its filled with JSON then you are getting a return value, but may need to Parse it using Parse JSON to gain access to the values.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

@Pstork1 I was able to return a result set once I provided a JSON sample with a smaller data set. I guess my original was too large. However, I'm still unable to return the fields from the resultset to powerapps. It's only returning two unknown columns "items" & "type".

Capture (1).JPGCapture (2).JPGCapture (3).JPG

If I try to parse and then use "Respond To Power Apps" step, I can only see "type" as a field and not my actual fields from my stored procedure:

Capture (4).JPG

here is my JSON schema:

{
    "type": "object",
    "properties": {
        "ResultSets": {
            "type": "object",
            "properties": {
                "Table1": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "Id_TraineeSignedTask": {
                                "type": "integer"
                            },
                            "Trainee_Id": {
                                "type": "integer"
                            },
                            "Task_Id": {
                                "type": "integer"
                            },
                            "TrainerAtTimeOfTraineeSignature": {
                                "type": "string"
                            },
                            "CourseVersion_Id": {
                                "type": "integer"
                            },
                            "Note": {
                                "type": "string"
                            },
                            "Id_TrainerSignedTask": {
                                "type": "integer"
                            },
                            "TraineeSignedTask_Id": {
                                "type": "integer"
                            },
                            "TrainerSignatureTime": {
                                "type": "string"
                            },
                            "TrainerName": {
                                "type": "string"
                            },
                            "TaskStatus": {
                                "type": "string"
                            }
                        },
                        "required": [
                            "Id_TraineeSignedTask",
                            "Trainee_Id",
                            "Task_Id",
                            "TrainerAtTimeOfTraineeSignature",
                            "CourseVersion_Id",
                            "Note",
                            "Id_TrainerSignedTask",
                            "TraineeSignedTask_Id",
                            "TrainerSignatureTime",
                            "TrainerName",
                            "TaskStatus"
                        ]
                    }
                }
            }
        },
        "OutputParameters": {
            "type": "object",
            "properties": {}
        }
    }
}
Pstork1
Dual Super User III
Dual Super User III

A couple of suggestions.

1) You can use Data Select and Filter Array to remove unneeded rows and columns from your results to decrease the size of the result you want to return

2) You can't use Respond to Power Apps to return a data set.  Respond to Power Apps can only return a single object with some properties.  You need to use HTTP response if you want to return a full array of data to be stored in a collection.  Your HTTP response action in your flow should be the last action in your flow.

3) Based on your schema you are only returning a single object from SQL, not an array of data.  



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Ok, after extensive testing and trial and error, I got it working. I guess I had to change the name of the SQL step to "Execute a SQL Query" even though its a Stored Procedure task.

Capture.JPG

 

Add an expression to the response task in the Body field:

body('Execute_a_SQL_query').ResultSets.Table1

Capture2.JPG

and now it works fine. The only thin I was doing different in my previous attempts was the SQL task name was different. It still matched my Response expression but only once I changed it to "Execute a SQL Query" did it start working. Seems strange to me.

I'm also disappointed by the limitations of this method i.e. can't return data type image and I can't return a time converted to an integer. After 4 days of trial and error, I'll take what I can get.

View solution in original post

Pstork1
Dual Super User III
Dual Super User III

Just to be clear.  You do not need to run this as Execute SQL Query.  You can run it as Execute Sql Stored Procedure.  Your previous screenshots show you processing the results set, not the results set Table.  I suspect that is where the problem lies.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

@Pstork1 

Unfortunately I can not prove otherwise. I even created a new Flow to test. Everything is exactly the same except the SQL name. They both run fine in Flow. BUT in Power Apps, only one of them can be stored in a collection. I guess it's a Power Apps issue.

Capture.JPG

Capture4.JPG

 

Pstork1
Dual Super User III
Dual Super User III

 

 

I would need to see your stored procedure to figure out why its not working for you, but I can show you several examples where I call a flow from a Power App, run a stored procedure, and return the results back to a collection in Power apps.  It does work.  I'm not sure why it won't work for you.  Here's just one example

image.png

image.png



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

@Pstork1 thank you for the help. Here is my SPROC:

 

ALTER PROCEDURE [dbo].[spSccSignedTasksByTraineeId] @TraineeId int
AS
SET NOCOUNT ON;
SELECT [Id_TraineeSignedTask]
      ,[Trainee_Id]
      ,[Task_Id]
      ,[TrainerAtTimeOfTraineeSignature]
      ,[CourseVersion_Id]
      ,[Note]
      ,[Id_TrainerSignedTask]
      ,[TraineeSignedTask_Id]
      ,[TrainerSignatureTime]
      ,[TrainerName]
      ,[TaskStatus]
FROM vSccSignedTasks
WHERE Trainee_Id = @TraineeId
Pstork1
Dual Super User III
Dual Super User III

What Data types are the SQL fields you are returning?  



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

I crossed off the fields i'm not pullin into the SPROC, but this is the view I'm referencing:

Capture.JPG

Pstork1
Dual Super User III
Dual Super User III

So I put together a quick SQL database with the columns in your Stored Proc. And added the same stored proc.  Then a simple Power app to run the stored Proc, return the collection and display in a gallery.  It worked fine for me.  My only change was to run the stored proc on the table instead of a view.  But that shouldn't change anything.

image.png

image.png



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

So incredibly strange. I guess this will just have to go down as an unsolved mystery for me. At least it's working now for me. I appreciate all of your feedback on this.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,179)