Managing Custom Settings in Power Apps: A Complete Guide to Setting Components and Programmatic Control

Managing Custom Settings in Power Apps: A Complete Guide to Setting Components and Programmatic Control

Power Apps is a powerful platform for building custom business solutions. One of the key features that enhances customization and flexibility is the Setting component. This component allows administrators and customizers to enable or disable specific settings/features within a solution. Combined with programmatic control through Xrm.Utility.getGlobalContext(), settings can be dynamically managed across environments and apps.

In this article, we’ll walk through how to set up and manage custom settings in Power Apps using both the Setting component and programmatic methods for setting and retrieving values.

1. Understanding the Setting Component

In Power Apps, the Setting component allows you to define configuration settings that can be applied either at the Environment or App level. This component ensures that you can customize your app’s behavior based on specific requirements, whether for the entire environment or individual apps.

How to Set Up the Setting Component

To set up a Setting component, follow these steps:

  1. Navigate to Your Solution Go to the solution in Power Apps where you want to create the setting.
  2. Create a New Setting Definition From the solution, click: NewMoreSettingSetting definition.


Article content

  1. Configure the Setting This opens a side pane where you can configure the setting’s:
  2. Define Scope In the property "Value can be changed for", choose whether the setting applies to the Environment, App, or Both. This allows for granular control over which parts of your solution the setting will impact.


Article content

Save the Setting Once saved, a Setting Definition Record is created, which can be accessed programmatically.


2. Programmatically Managing Custom Settings

Now, let's take it a step further: managing settings dynamically through code. With Xrm.Utility.getGlobalContext(), you can retrieve and change custom setting values at runtime. This adds an extra layer of flexibility for handling settings based on specific user or app conditions.

Step 1: Fetching a Custom Setting Value

Use the getCurrentAppSetting method to retrieve the value of a custom setting that has been defined. For instance, let’s say you have created a custom setting "crfee_mycustomsetting" :

Xrm.Utility.getGlobalContext().getCurrentAppSetting('crfee_mycustomsetting');

Or

<fetch>

<entity name="settingdefinition" >

<attribute name="defaultvalue" />

<attribute name="overridablelevel" />

<attribute name="isoverridable" />

<filter>

<condition attribute="uniquename" operator="eq" value="crfee_mycustomsetting" />

</filter>

<link-entity name="organizationsetting" from="settingdefinitionid" to="settingdefinitionid" link-type="outer" alias="OrgSetting" >

<attribute name="value" />

</link-entity>

</entity>

</fetch>

Output : false (as we set the default value as false)


Article content

Step 2: Setting a Custom Setting Value

You can also change the setting value using the saveSettingValue method. Here, we set the crfee_mycustomsetting to true:

Xrm.Utility.getGlobalContext().saveSettingValue('crfee_mycustomsetting', true, { overrideScope: 1, solutionUniqueName: "Test" })

The overrideScope parameter controls where the setting is applied:

  • 1 – Environment level.
  • 2 – App level.
  • 3 – Both.


Article content

So we programmatically updated our custom setting value as true.

3. Why Custom Settings Matter

Custom settings allow you to:

  • Store and retrieve configuration values that control features or behaviors in your app.
  • Dynamically enable or disable certain functionalities based on user needs.
  • Customize app behavior based on environment-specific configurations, providing flexibility across development, testing, and production stages.

This makes your app more adaptable, scalable, and easier to manage.

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics