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
Properties

No properties

Methods
Constructor

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');
}
}
Platforms

📳 Devices: All Clouds: All

App Types

📳 Mobile 🌐 Backend

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

Description
Parameters
Returns
Example
Description

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.

Parameters
  • key: string the name of the setting. it must not contain only letters and digits and no spaces

Returns

Returns a string if there is stored valu under the given key. Returns undefined if there NO stored value under the given key

Example

let value = await this.ConfigurarationService.getSetting('mySetting');
console.log(value);//will either print sting value or undefined

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

Description
Parameters
Returns
Example
Description

Method setSetting stores a value for the given key. The value can be later read via the getSetting method.

Parameters
  • 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

Returns

void

Example

import { ConfigurationService } from '@dms';
...
await this.ConfigurationService.setSetting('dateformat','yyyyMMdd');

How to use

Example

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);
}
}