Comment on page
ConfigurationService
ConfigurationService TypeScript Class Reference
SERVICE
This class is a "service" and it is automatically injected if declared as a member in the constructor of the consuming class.
- See the constructor section below for details
- See the Automatic Instance Injection page for details on the topic
The ConfigurationService class provides methods to read and write settings. Dynamics Mobile apps can store key-value pairs, which then can be read from the app via the ConfigurationService class. These key-value pairs can be provided by the system administrator of Dynamics Mobile application area. This allows the developer to design the app, so that it may change its behavior based on the settings provided by the administrator. For example such setting can be the color of the Home page or format of the date and time fields displayed in the app.
The ConfigurationService can also be used to persist key-value pairs locally on the device , which survive application restarts.
Do not store heavy pieces of data in the ConfigurationService, because it may impact the performance of the app. The ConfigurationService must ideally must store string key/value pairs where every key and/or value is not longer than 50 characters.
Properties
Methods
Constructor
Platforms
App Types
No properties
- getAllSettings
- getAllowedTasks
Don't instantiate directly instances of the ConfigurationService class.
ConfigurationService instances are automatically injected by Dynamics Mobile framework.
import {View, ConfigurationService} from '$dms';
@View()
export class MyView {
constructor(
//we need to only declare the member
private ConfigurationService: ConfigurationService
){
}
async load(){
//we can now use the injected instance
let value = await this.ConfigurationService.getSetting('mysetting');
}
}
Devices: All
Clouds: All
📳
☁
📳
🌐
Description
Parameters
Returns
Example
The getSetting method returns the value stored under the key given as method argument. It will return undefined if there is no setting with the given key.
- key: string the name of the setting. it must not contain only letters and digits and no spaces
Returns a string if there is stored valu under the given key.
Returns undefined if there NO stored value under the given key
let value = await this.ConfigurarationService.getSetting('mySetting');
console.log(value);//will either print sting value or undefined
Description
Parameters
Returns
Example
Method setSetting stores a value for the given key. The value can be later read via the getSetting method.
- key: string - the name of the setting. it must not contain only letters and digits and no spaces
- value: string - the value of the key. The value can be then read via the getSetting method
void
import { ConfigurationService } from '@dms';
...
await this.ConfigurationService.setSetting('dateformat','yyyyMMdd');
import { Formatters, View, ConfigurationService } from '@dms';
@View()
export class MyView {
constructor(private Formatters: Formatters, private ConfigurationService: ConfigurationService){
}
async load(){
let format = await this.ConfigurationService.getSetting('dateformat');
let date = new Date();
let dateAsString = date.format(format);
console.log(dateAsString);
}
}
Last modified 3yr ago