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.

No properties

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

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.

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

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

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

}

Last updated

Dynamics Mobile provided by Mobile Affairs Ltd. | 1712 Sofia, Bulgaria, Alexander Malinov 51 | sales@dynamicsmobile.com