DocumentSeriesService

DocumentSeriesService 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 DocumentSeriesService class provides methods to consume local (on-device) document series. The document series feature allows the developer to generate unique number sequences as needed, where the actual format of the number sequences can be controlled by the system administrator. This feature is used in functionalities like invoice and order number generation as well as any other document number generation scenarios, where each document type must have separate number sequence.

Properties
Methods
Constructor
Platofrms
App Types
Properties

No Properties

Constructor

Don't instantiate directly instances of the DocumentSeriesService class.

DocumentSeriesService instances are automatically injected by Dynamics Mobile framework.

import {View, DocumentSeriesService} from '$dms';
@View()
export class MyView {
constructor(
//we need to only declare the member
private DocumentSeriesService: ContextService
){
}
async load(){
//we can now use the injected instance
let value = await this.DocumentSeriesService.getCurrentNumber(0);
}
}
Platofrms

📳 Devices: All Clouds: All

App Types

📳 Mobile 🌐 Backend

getCurrentNumber(documentType: number): Promise<string>

Description
Parameters
Returns
Example
Description

getCurrentNumber method return the current number for a given document series uniquely defined by the documentType argument.

Parameters
  • documentType: number integer value uniquely identifying the document type for which the current value must be obtained

Returns

Returns string value, which represent the current number for the given documentType

Example

import { DocumentSeriesService } from '@dms';
...
var myDocumentNumber = await DocumentSeriesService.getCurrentNumber(0);
console.log(myDocumentNumber); // outputs 1

getNextNumber(documentType: number): Promise<string>

Description
Parameters
Returns
Example
Description

getNextNumber method return the next number for a given document series, uniquely defined by the documentType argument. Note that calling getNextNumber multiple times with the same value for documentType argument, will return the same value always, unless incrementNumber method is called

Parameters
  • documentType: number integer value uniquely identifying the document type for which the next value must be obtained

Returns

Returns string value representing the next number for the given documentType

Example

import { DocumentSeriesService } from '@dms';
...
var myDocumentNumber = await DocumentSeriesService.getNextNumber(0);
console.log(myDocumentNumber); // outputs 2

increaseNumber(documentType: number): Promise<string>

Description
Parameters
Returns
Exmaple
Description

ncrementNumber method return the next number for a given document series uniquely defined by the documentType argument and persists the new value, e.g. making it current. Note that calling incrementNumber multiple times with the same value for documentType argument, will return different value (incremental) every time.

Parameters
  • documentType: number - integer value uniquely identifying the document type for which the value must be incremented

Returns

Returns the next number for a given document series, uniquely defined by the documentType argument.

Exmaple

import { DocumentSeriesService } from '@dms';
...
var myDocumentNumber = await DocumentSeriesService.incrementNumber(0);
console.log(myDocumentNumber); // outputs 2

How to use

import { View, DocumentSeriesService, UserInterfaceService } from '@dms';
import { Invoice } from '@dms-bo';
// it is supposed that there is defined business object Invoice in the Business Object folder
@View()
export class MyView {
constructor(
private DocumentSeriesService: DocumentSeriesService,
private UserInterfaceService: UserInterfaceService){
}
createInvoice = async ()=>{
//create new document
var document = new Invoice();
//get tne next number for displaying purposes
document.No = await this.DocumentSeriesService.getNextNumber(0);
this.UserInterfaceService.showMessage(`The new document number will be ${document.No}`); //expected to show 1
//persist increased document number and persist document
document.no = await this.DocumentSeriesService.increaseNumber(0);
//persist document in the local device database
await document.add();
//show the new number on the screen
this.UserInterfaceService.showMessage(`The new document number is ${document.No}`); //expected to show 1
var newDocNo = await this.DocumentSeriesService.getNextNumber(0);
console.log(newDocNo); //expected to show 2, because method increaseNumber was called before
}