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 / Calling a stored proce...
Power Apps
Unanswered

Calling a stored procedure in Power FX results in untyped objects - gateway issue?

(3) ShareShare
ReportReport
Posted on by 6

Hi,

 

I try to load data from SQL into a Power App by calling a stored procedure directly in Power FX using the new preview feature.

I did a test on developer tenant with some small tables in Azure SQL which worked perfectly.

Next I implemented basically the same setup in the actual app I wanted to use this in, and I'm now encountering the problem, that the data is always untyped. This happens even for very basic stored procedures, e.g. returning 10 rows with 2 columns, text only.

 

The main difference here is, that the production database is behind a data gateway. Is this even supported yet?

Categories:
I have the same question (0)
  • RoyBland Profile Picture
    12 on at

    Hi, I am having the exact same issue, did you find a solution?

    Thanks

  • AD-23070319-0 Profile Picture
    12 on at

    Found a solution on this post: https://www.reddit.com/r/PowerApps/comments/1c8hipu/comment/l0ev6t7/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

    Be sure to read over the Microsoft article about the preview SP feature in Power Apps and that you've added your stored procedure to your Power App through the SQL connector.

    https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/connections/connection-azure-sqldatabase#call-stored-procedures-directly-in-power-fx-preview

    Your syntax for calling stored procedures is incorrect. It should be:

    database.stored_procedure({args: values})

    If you are expecting a return query from your stored procedure, then it will get sent over as an untyped object under the ResultSets.Table1 child. This is exactly the same return format if the same stored procedure was invoked from Power Automate.

    In Power Apps:

    database.stored_procedure({args: values}).ResultSets.Table1

    In Power Automate:

    body('Execute_stored_procedure_(V2)')?['ResultSets']?['Table1']

    From here, you need to strictly type the untyped object in order to insert it into a collection, either using ForAll() or AddColumns().

    ClearCollect(
     colStoredProcedure,
     DropColumns(
     AddColumns(
     Table(database.stored_procedure({args: values}).ResultSets.Table1),
     Column1,
     Text(ThisRecord.Value.TextValue),
     Column2,
     Value(ThisRecord.Value.IntValue),
     Column3,
     DateValue(ThisRecord.Value.DateValue)
     ),
     Value
     )
    )

    As for invoking the stored procedure through Power Automate and sending it to Power Apps, the code is pretty much the same aside from needing to send the data over as a JSON string then wrapping your Run() in Power Apps with ParseJSON(). If your values are coming up blank, you need to troubleshoot what is happening through your flow.

    To answer your questions:

    1. The stored procedure feature is still in preview. As with all preview features, it's "use at your own risk" if you want to use it in a production environment.

    2. Once you strictly type an untyped object and put it in a collection, you should be able to filter the data like any other normal collection.

  • RoyBland Profile Picture
    12 on at

    Thank you for the info. 
    My code now runs and I am seeing the correct number of rows but all of the data is blank. 
    I appreciate that calling stored procedures is in preview and this is via a gateway but if anyone knows a workaround please let me know. 
    Thanks

  • AD-23070319-0 Profile Picture
    12 on at

    I am using a gateway as well, but it worked for me. Could you share your code? Maybe I can help spot the issue?

  • RoyBland Profile Picture
    12 on at

    Hi Ambdeep

    Thank you for offering to check over my code.

     

        nfUserMenu =

            DropColumns(AddColumns(

                Table(PoolMaintenance_1.dbospMenuForRole(

                    {

                        LoginName: nfCurrentUser.LoginName,

                        MenuName: "Main"

                    }

                ).ResultSets.Table1)

                , MenuName,Text(ThisRecord.Value.TextValue)

                , MenuItemIcon,Text(ThisRecord.Value.TextValue)

                , MenuItemText,Text(ThisRecord.Value.TextValue)

                , MenuItemScreenToGoTo,Text(ThisRecord.Value.TextValue)

                , MenuItemOrder,Value(ThisRecord.Value.IntValue)

                , Screen,Text(ThisRecord.Value.TextValue)

                ), Value

            )

        ;

     

  • AD-23070319-0 Profile Picture
    12 on at

    Hi Roy,

     

    I see the issue, you need to replace TextValue with your column name. For eg. if your column in SQL is called "Menu_Name" then the expression should read: MenuName,Text(ThisRecord.Value.Menu_Name)

     

    Hope this helps

  • RoyBland Profile Picture
    12 on at

    Thank you, that works the way I want it to now, your help is much appreciated.

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 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard