top of page
Writer's pictureAlan Campbell

Custom Connectors Mastery: Python & Power Apps - Part 3

Updated: Oct 30, 2023

In the third installment of our enlightening series on the seamless integration of Python Script Function Apps with Power Apps using Azure Function Apps, we steer our focus towards the riveting world of Microsoft Power Apps. A tool that has revolutionized the development landscape, Power Apps facilitates the smooth integration with various data platforms, offering a dynamic environment that even those with no background in coding can navigate with ease.


In this part of our series, we dive deep into the practical applications of the custom connector we meticulously crafted in part 2. Guiding you through the critical steps of registering and calling the custom connector within the Power App, we aim to further hone your skills in manipulating this powerful tool. Be prepared to unveil the potential of leveraging parameters to call the custom connector and mastering the art of capturing and saving the vital data obtained from the responses of the custom connector.


Beginning with the fundamental step of adding the custom connector to your Power App, we will walk you through the processes involved, ensuring you acquire a firm grasp on the techniques required to make the most out of your Power App environment. Whether it's learning to call the ‘GetStatistics’ action appropriately or understanding how to decipher and isolate the JSON response to save critical data elements efficiently, we've got you covered.


As we delve into the nuances of utilizing the X and Y parameters representing months and corresponding sales data, we equip you with the know-how to create a functioning system that not only calls actions with precision but also intelligently handles responses, paving the path for sophisticated data handling and presentation in your Power Apps.


Integrating Your Custom Connector


The first thing we want to do is add the custom connector to your Power App. To do this click on Data in the left navigation pane and then click on Add data.

This image shows where to click on the Data button in the left navigation pane in Power Apps.
Click on Data in the Left Navigation Pane to Add Your Custom Connector

The next step is to search for the Statistics custom connector by name and select it. The custom connector should now show in your Data list.

This image shows where to enter the Statistics custom connector  in Microsoft Power Apps
Enter the Custom Connector Named Statistics in the Search Field

Calling the Custom Connector


Calling the Statistics custom connector requires that you call the Action associated with the custom connector. In the prior blog we created the GetStatistics action when we created the custom connector.


The GetStatistics action requires two string parameters. The first parameter is the X parameter and specifies a list of months. The second parameter is the Y parameter and specifies the sales for the months. Both parameters should contain the same number of elements in the list. Here is a hardcoded example of how to call the GetStatistics action:


Statistics.GetStatistics(
    "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14",
    "4535,3887,6477,4534,6477,3239,5182,5182,2592,3888,1944,3239,5829,3886,4000"
); 

Getting the Response


The GetStatistics action returns a JSON that contains the following elements:


{
    "slope": -96.64999999999999,
    "intercept": 5002.616666666667,
    "r": -0.3247983548185419,
    "p": 0.2375335363376549,
    "std_err": 78.05630651766381
}

Capture the GetStatistics response in the statisticsResponse variable by using an UpdateContext as shown below. We wrap the UpdateContext around the GetStatistics call.


UpdateContext(
    {
        statisticsResponse: Statistics.GetStatistics(
            "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14",
            "4535,3887,6477,4534,6477,3239,5182,5182,2592,3888,1944,3239,5829,3886,4000"
        )
    }
);

Then, save each of the response elements by using an UpdateContext as shown below for three of the five elements. We will use the slope, intercept, and r values in later blogs.


UpdateContext(
    {
        slope: statisticsResponse.slope,
        intercept: statisticsResponse.intercept,
        r: statisticsResponse.r
    }
);

Conclusion


As we draw the curtain on part 3 of our invigorating series on Python Script Function Apps and Power Apps utilizing Azure Function Apps, we trust that you are now more adept with the rich features of Microsoft Power Apps. Our journey today allowed us to unravel the remarkable potential that Power Apps holds in seamlessly integrating with various data platforms, a capability that stands as a testament to its transformative power in the developmental landscape.


We embarked on this leg of the series with a detailed walkthrough on integrating your custom connector, a skill crucial in leveraging the bountiful resources Power Apps offers. With each step, we ventured deeper into the practices of registering, calling, and capturing responses from the custom connector, ensuring a comprehensive understanding that would enable you to unravel the secrets lying in the heart of data handling through Power Apps.


In this intricate pathway, we guided you in grasping the essence of invoking the ‘GetStatistics’ action through precise parameter usage, embodying months and sales data. Through hands-on demonstrations, we unveiled the methodologies to meticulously extract, analyze, and save the pivotal data elements returned in the JSON response, a skill pivotal in isolating and harnessing the necessary insights for your projects.


With a focus on practicality, this segment aimed at nurturing a competency in handling responses intelligently, giving rise to a sophisticated data handling mechanism that stands to elevate your Power Apps presentations to unprecedented heights.


As we stand on the threshold of the next adventure in this series, we invite you to carry forward the skills and understanding cultivated in this chapter. The journey ahead promises even more exciting revelations and opportunities to refine your prowess in navigating the vibrant ecosystem of Business Central through the confluence of Python scripts and Power Apps.


We hope you are leaving this segment with a treasure trove of knowledge and an eagerness to delve even deeper into the world of Power Apps. Stay tuned as we continue to forge paths in the dynamic landscape of app development, driving innovation and facilitating seamless integrations to empower you in achieving your objectives with efficiency and finesse. Thank you for joining us in this enriching exploration, and we eagerly await to guide you in the forthcoming chapters of this enthralling series. Stay curious, stay inspired!




688 views0 comments

Comments


bottom of page