How to directly access Custom Action from Custom Pages in Power Apps

By | January 11, 2024

Power Apps offers versatile design experiences, including model-driven apps and Canvas apps, and the recent addition of Custom Pages. Based on the client’s recent requirements, we had to replace the OOB Opportunity entity with the custom one. In response to our client’s specific requirements, we meticulously recreated essential functionalities, such as the “Opportunity Close as Won” and “Close as Lost” processes. Notably, these functionalities were expertly crafted using Custom Pages to introduce a streamlined and tailored user interface, effectively replacing the default popups. So for the agenda of this blog, we will focus on how we used the Custom action in the Custom page to recreate the Opportunity close functionality in the custom Opportunity Entity.

Custom Action from Custom Pages in Power Apps

Step 1:

As we know, once the Opportunity is closed, one new record gets created in the Opportunity close Entity regarding that record, and the status of the Opportunity record gets changed. All these things can be done with the help of the custom action.

To call the Custom action On the Custom page, we have to enable one setting and make sure this is enabled.

1. Go to settings.

2. Go to Upcoming features.

3. Enable access to Microsoft Dataverse Actions.

Custom Action from Custom Pages in Power Apps

This feature is available in the previously created apps. For newly created apps, this feature has been automatically enabled ever since the general availability of this feature. Even if you are not able to access the custom action on the custom page, then do the below list of actions.

1. Go to settings

2. Go to Upcoming features.

3. Go to the retired section.

4. Make sure this feature, ‘Disable access to Microsoft Dataverse actions, is disabled, as seen below in the highlighted part.

Custom Action from Custom Pages in Power Apps

Note – Please do not get confused by seeing the retired setting. Refer to the given links for more information that indicates general availability: https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/connections/connection-common-data-service#call-dataverse-actions-directly-in-power-fx and https://powerapps.microsoft.com/en-us/blog/direct-power-fx-dataverse-action-invocation-ga/

Step 2:

After this, you have to add the Environment entity and all the entities that you require on the Custom page.

Custom Action from Custom Pages in Power Apps

Step 3:

In the process of enhancing the Custom Opportunity Entity with a Close Opportunity Modal using Custom Pages in Power Apps, it becomes imperative to set default values for specific fields on the Custom Page. This task is accomplished through Power FX formulas.

Step 4:

The final step involves invoking a custom action upon clicking the ‘OK’ button. This process utilizes the Environment table to access and execute actions available within the CRM environment. The following steps provide a formal guide for calling the custom action and configuring inputs based on the specific requirements.

1. Input parameters are defined in the action, as seen below.

Custom Action from Custom Pages in Power Apps

2. Set the values for the variables as shown below.

Custom Action from Custom Pages in Power Apps

3. Identify and select the custom action from the available actions within the Environment table (in our case, it is e8s_Create_ClosedOpportunity). This action is responsible for closing the Opportunity and creating a record in the Opportunity Close Entity.

4. Referencing the provided image, add inputs to the selected custom action. This step involves configuring the inputs required for the action to operate successfully.

Custom Action from Custom Pages in Power AppsStep 5:

It’s crucial to handle the output parameter from the custom action. Specifically, we aim to retrieve the ‘Opportunity Close’ record’s ID generated upon closing the opportunity. This information is then used to determine whether the action was successful, closing the Custom Page accordingly, or displaying an error message if the record creation fails. Within the custom action configuration, ensure that the ‘Opportunity Close’ record ID is specified as an output parameter.

Conclusion

This blog explained the process of invoking a custom action from Power Apps to close opportunities and create related records, emphasizing the importance of handling output parameters for a successful user experience. Overall, the guide showcased the flexibility of Power Apps in creating tailored solutions for efficient business processes.

Microsoft Power Platform