web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Get a ReturnCode in SQ...
Power Apps
Answered

Get a ReturnCode in SQL Stored Procedures

(1) ShareShare
ReportReport
Posted on by 37
I have created this SQL Stored Procedure
 
CREATE PROCEDURE [dbo].[sp_RegistrarAccesoInvitacionNoNumerada]
    @IdEvento INT,
    @Puerta INT
AS
BEGIN   
	BEGIN TRY
        INSERT INTO CONTROLACCESOEVENTOS_REGISTROINVITACIONESNONUMERADAS
        VALUES (@IdEvento, GETDATE(), @Puerta);
		RETURN 0;  -- Success;
    END TRY
    BEGIN CATCH
        RETURN -1; -- Error
    END CATCH
END
I invoke it from PowerApps with this code:
 
UpdateContext({
    varRegistroResultadoProcedimientoAlmacenado:
    sp_InvitacionesNoNumeradas.dbospRegistrarAccesoInvitacionNoNumerada({
        IdEvento:varEventID,
        Puerta:varIdPuerta
    })
});

UpdateContext({
    varResultadoProcedimientoAlmacenado: 
    varRegistroResultadoProcedimientoAlmacenado.ReturnCode
});
The procedure executes well. The values are inserted in the database, but I don't get any ReturnCode. This is my 'varRegistroResultadoProcedimientoAlmacenado' record:
 
 
No OutputParameters (ok), no ResultSets (ok, too), but... no ReturnCode? It should be 0 or -1
 
Can you tell me how can I check the execution of my Stored Procdeure?
 
Thanks! :)
 
 
 
Categories:
I have the same question (0)
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,969 Moderator on at
  • Verified answer
    FG-11091158-0 Profile Picture
    37 on at
    I tried EVERYTHING (ReturnCode, OutputParameters...) and, at the end, the only solution I found was to get the 'ReturnCode' as a ResultSet:
     
    ALTER PROCEDURE [dbo].[sp_RegistrarAccesoInvitacionNoNumerada]
        @IdEvento INT,
        @Puerta INT,
    @Resultado INT OUTPUT
    AS
    BEGIN   
        BEGIN TRY
            INSERT INTO CONTROLACCESOEVENTOS_REGISTROINVITACIONESNONUMERADAS
            VALUES (@IdEvento, GETDATE(), @Puerta);
            -- Return 0 (success)
            RETURN 0;  -- as ReturnCode;
            SET @Resultado = 0;  -- as OutputParameters
            SELECT 0 AS Res;  -- as ResultSet
        END TRY
        BEGIN CATCH
            -- Return -1 (error)
            RETURN -1;  -- as ReturnCode;
            SET @Resultado = -1;  -- as OutputParameters
            SELECT -1 AS Res;  -- as ResultSet
        END CATCH
    END
    Called the procedure:
     
    UpdateContext({
        var:
        sp_InvitacionesNoNumeradas.dbospRegistrarAccesoInvitacionNoNumerada({
            IdEvento: varEventID,
            Puerta:varIdPuerta
        })
    })
    And read the results:
     
    UpdateContext({
        ReturnCode_Try1: var.ReturnCode,    // Got Nothing
        ReturnCode_Try2: var.OutputParameters.Resultado,  //Got Nothing
        ReturnCode_Try3: Value(First(var.ResultSets.Table1).Res)  //Ok!!!
    })
     
    Only ReturnCode_Try3 gave me what I neded
     
    Hope it helps anyone with the same problem :)
     
    NOTE:

    As stated in the post recommended by Michael:

    Power Apps Guide - SQL - How to return data from Stored Procedures to Power Apps - Power Apps Guide - Blog
     
    You can get MULTIPLE resultsets. So, if your stored procedure returs a ResultSet with data, you can send the 'returncode' in a second table.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 536

#2
WarrenBelz Profile Picture

WarrenBelz 426 Most Valuable Professional

#3
Haque Profile Picture

Haque 305

Last 30 days Overall leaderboard