Can someone please help me understand why I'm not able to see a ResultSet from my Stored Procedure. I only return an Output.
Solved! Go to Solution.
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.
Add an expression to the response task in the Body field:
body('Execute_a_SQL_query').ResultSets.Table1
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.
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.
@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".
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:
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": {}
}
}
}
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.
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.
Add an expression to the response task in the Body field:
body('Execute_a_SQL_query').ResultSets.Table1
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.
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.
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.
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
@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
What Data types are the SQL fields you are returning?
I crossed off the fields i'm not pullin into the SPROC, but this is the view I'm referencing:
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.
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.
User | Count |
---|---|
27 | |
14 | |
12 | |
10 | |
9 |
User | Count |
---|---|
50 | |
29 | |
28 | |
24 | |
20 |