cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Display return code of stored procedure in PowerApp

Hello,

 

I have a button in PowerApps which executes a stored procedure and I want to display a message if the stored procedure was executed successfully or not. I have tried doing this by adding an output but I cannot get the result to be displayed in a text field in PowerApps. 

Has anyone tried this successfully?

returncode.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Pstork1
Dual Super User
Dual Super User

Have you tried storing the return code from the Flow in a variable in PowerApps and then binding the textbox to the variable.  As a declarative system PowerApps doesn't normally allow programmatic changes to object properties at runtime.  Usually you have to bind controls to variables and then change the value of the variable.

 YOur run statement should look something like this.

Set(returnvariablename, Flowname.run(input parameters if any))


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

Join me at 365EduCon in Chicago on Sept. 26-30 where I'll be presenting on the Power Platform!

View solution in original post

8 REPLIES 8
Pstork1
Dual Super User
Dual Super User

Have you tried storing the return code from the Flow in a variable in PowerApps and then binding the textbox to the variable.  As a declarative system PowerApps doesn't normally allow programmatic changes to object properties at runtime.  Usually you have to bind controls to variables and then change the value of the variable.

 YOur run statement should look something like this.

Set(returnvariablename, Flowname.run(input parameters if any))


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

Join me at 365EduCon in Chicago on Sept. 26-30 where I'll be presenting on the Power Platform!
Anonymous
Not applicable

Hello @Pstork1 ,

 

This is what I did, but the text field displays no value.  

 

Set(datafromflow, ExecuteSP.Run())variable.PNGText field.PNG

Did you look at the variable value itself using the menu in the designer to make sure that there was a return code?  That will tell you if its just not binding or if there is a problem saving the return code from the stored procedure and returning it to Powerapps.  It might be a Flow or a SQL issue rather than a PowerApps issue.



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

Join me at 365EduCon in Chicago on Sept. 26-30 where I'll be presenting on the Power Platform!
Anonymous
Not applicable

@Pstork1 ,

 

where can I see the return code in designer? I can see the data from the below print screen, but I am not sure if it is the right thing. Thank you.retunrcode.PNG

Nope, that's the right place.  But if you look down into the Outputs section you will see that your result code is blank.  Double check your stored procedure to make sure its actually returning a result code.



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

Join me at 365EduCon in Chicago on Sept. 26-30 where I'll be presenting on the Power Platform!
Anonymous
Not applicable

Hello @Pstork1 ,

 

I have a return code in my procedure but it still does not return anything.

 

ALTER procedure [dbo].[TESTProc] as
BEGIN
SELECT 8/4
return 1
END

 

@Anonymous  i have this same issue, Did you made it work?

Anonymous
Not applicable

Hello @CodingCarnage ,

 

I used the following solution: 

In the stored procedure: 
DECLARE @ResultsTable TABLE (ErrorMessage varchar(500), ErrorCode VARCHAR(10), ReturnData NVARCHAR(MAX), ReturnMessage NVARCHAR(MAX))

Insert the desired values in the table: 

INSERT INTO @ResultsTable(ErrorMessage, ErrorCode, ReturnData , ReturnMessage)
VALUES ('1', '2', '3' , '4');

at the end of the stored procedure:

SET @JSON_OUTPUT= (SELECT ErrorMessage, ErrorCode, ReturnData , ReturnMessage from @ResultsTable FOR JSON AUTO, INCLUDE_NULL_VALUES )
end

 

In MS Flow use a parse JSON after the execution of the stored procedure:

https://ibb.co/w7cH6Rz

Put this in schema:

{
    "type""array",
    "items": {
        "type""object",
        "properties": {
            "ErrorMessage": {
                "type": [
                    "string",
                    "null"
                ]
            },
            "ErrorCode": {
                "type": [
                    "string",
                    "null"
                ]
            },
            "ReturnData": {
                "type": [
                    "string",
                    "null"
                ]
            },
            "ReturnMessage": {
                "type": [
                    "string",
                    "null"
                ]
            }
        }
    }
}
Add a respond to a PowerApp or Flow node: https://ibb.co/0KPwPgm
Then you call the flow in PowerApps UpdateContext({flowResult: Flow.run(parameters of flow)})
Hope this helps.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (3,484)