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

Notifications

Announcements

Community site session details

Community site session details

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

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,345 Super User 2025 Season 2 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard