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

getCurrentNumber(documentType: number): Promise<string>

Description
Parameters
Returns
Example
getCurrentNumber method return the current number for a given document series uniquely defined by the documentType argument.
    documentType: number integer value uniquely identifying the document type for which the current value must be obtained
Returns string value, which represent the current number for the given documentType
1
import { DocumentSeriesService } from '@dms';
2
3
4
...
5
var myDocumentNumber = await DocumentSeriesService.getCurrentNumber(0);
6
console.log(myDocumentNumber); // outputs 1
7
Copied!

getNextNumber(documentType: number): Promise<string>

Description
Parameters
Returns
Example
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
    documentType: number integer value uniquely identifying the document type for which the next value must be obtained
Returns string value representing the next number for the given documentType
1
import { DocumentSeriesService } from '@dms';
2
3
4
...
5
var myDocumentNumber = await DocumentSeriesService.getNextNumber(0);
6
console.log(myDocumentNumber); // outputs 2
Copied!

increaseNumber(documentType: number): Promise<string>

Description
Parameters
Returns
Exmaple
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.
    documentType: number - integer value uniquely identifying the document type for which the value must be incremented
Returns the next number for a given document series, uniquely defined by the documentType argument.
1
import { DocumentSeriesService } from '@dms';
2
3
4
...
5
var myDocumentNumber = await DocumentSeriesService.incrementNumber(0);
6
console.log(myDocumentNumber); // outputs 2
Copied!

How to use

1
import { View, DocumentSeriesService, UserInterfaceService } from '@dms';
2
import { Invoice } from '@dms-bo';
3
4
// it is supposed that there is defined business object Invoice in the Business Object folder
5
6
@View()
7
export class MyView {
8
9
constructor(
10
private DocumentSeriesService: DocumentSeriesService,
11
private UserInterfaceService: UserInterfaceService){
12
13
}
14
15
createInvoice = async ()=>{
16
//create new document
17
var document = new Invoice();
18
//get tne next number for displaying purposes
19
document.No = await this.DocumentSeriesService.getNextNumber(0);
20
21
22
this.UserInterfaceService.showMessage(`The new document number will be ${document.No}`); //expected to show 1
23
24
25
//persist increased document number and persist document
26
document.no = await this.DocumentSeriesService.increaseNumber(0);
27
//persist document in the local device database
28
await document.add();
29
//show the new number on the screen
30
this.UserInterfaceService.showMessage(`The new document number is ${document.No}`); //expected to show 1
31
32
var newDocNo = await this.DocumentSeriesService.getNextNumber(0);
33
console.log(newDocNo); //expected to show 2, because method increaseNumber was called before
34
35
}
Copied!
Last modified 1yr ago