ConfigurationService
ConfigurationService TypeScript Class Reference

Overview

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
Don't instantiate directly instances of the ConfigurationService class.
ConfigurationService instances are automatically injected by Dynamics Mobile framework.
1
import {View, ConfigurationService} from '$dms';
2
3
@View()
4
export class MyView {
5
6
constructor(
7
//we need to only declare the member
8
private ConfigurationService: ConfigurationService
9
){
10
11
}
12
13
async load(){
14
//we can now use the injected instance
15
let value = await this.ConfigurationService.getSetting('mysetting');
16
17
}
18
19
}
Copied!
📳
Devices: All
Clouds: All
📳
Mobile
🌐
Backend

getSetting(key: string): Promise<string|undefined>

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
1
let value = await this.ConfigurarationService.getSetting('mySetting');
2
console.log(value);//will either print sting value or undefined
Copied!

setSetting(key: string, value: string | undefined): Promise<void>

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
1
import { ConfigurationService } from '@dms';
2
3
...
4
5
await this.ConfigurationService.setSetting('dateformat','yyyyMMdd');
Copied!

How to use

Example

1
import { Formatters, View, ConfigurationService } from '@dms';
2
3
4
@View()
5
export class MyView {
6
7
constructor(private Formatters: Formatters, private ConfigurationService: ConfigurationService){
8
9
}
10
11
async load(){
12
let format = await this.ConfigurationService.getSetting('dateformat');
13
let date = new Date();
14
let dateAsString = date.format(format);
15
console.log(dateAsString);
16
}
17
18
}
Copied!
Last modified 1yr ago