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:
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" />
Recommended by LinkedIn
<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)
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:
So we programmatically updated our custom setting value as true.
3. Why Custom Settings Matter
Custom settings allow you to:
This makes your app more adaptable, scalable, and easier to manage.