BusinessObjectBase
BusinessObjectBase TypeScript Class Reference

Overview

BusinessObjectBase class is a base class for all business objects. The developer defines the business objects within the app in JSON files (Business Object Definition) under the Business Objects folder in the app's project. The Dynamics Mobile framework will generate corresponding TypeScript implementations, where each of the Business Objects JSON definitions will be represented by a corresponding TypeScript class. Each of these TypeScript classes extends BusinessObjectBase class.
Don't create BusinessObjectBase class directly - use the automatically generated ancestors.
Properties
Methods
Constructor
Platforms
App Types
Name
Type
DMS_ROWID
string
members
string
appCode
string
boName
string
string
string
boolean
state
number
Name
query
livelinkQuery
add
update
delete
Do not create BusinessObjectBase instances directly. It is supposed that you have to create instances of the BusinessObjectBase ancestor classes, which are automatically generated during the build process in result of existing Business Object JSON definition files in your app's project.
1
import { Customer } from '@dms-bo';
2
...
3
var customer = new Customer();
Copied!
📳
Devices: All
Clouds: All
📳
Mobile
🌐
Backend

static appCode: string

Description
Example
Property 'appCode' contains the unique of the application where the business object was generated.
1
import { Customer } from '@dms-bo';
2
3
...
4
console.log(`current app code is ${Customer.appCode}`)
Copied!

static boName: string

Description
Example
Property 'boName' contains the name of the business object
1
import { Customer } from '@dms-bo';
2
3
...
4
console.log(`current business object name is ${Customer.boName}`)
5
//prints out: Customer
Copied!

static boSyncName: string

Description
Example
Property 'boSyncName' contains the synchronization tag of the business object as specified in the Business Object's JSON definition in the SyncTag property.
1
import { Customer } from '@dms-bo';
2
3
...
4
console.log(`current business object sync name is ${Customer.boSyncName}`)
5
//prints out: Customer
Copied!

static boTableName: string

Description
Example
Property 'boTableName' contains the name of the physical database table , where the records for the business object will be stored. Can be used in row level queries executed via SqlQueryService class.
1
import { Customer } from '@dms-bo';
2
import { SqlQueryService } from '@dms';
3
4
...
5
let sqlStatement = `select * from ${Customer.boTableName}`;
6
let records = await this.SqlQueryService.execute();
7
Copied!

static members: Array<BusinessObjectMember>

Description
Example
BusinessObjectMember
the property contains metadata for the properties of the business object as they are defined in the business object JSON definition.
1
import { Customer } from '@dms-bo';
2
import * as uuid from 'uuid'
3
...
4
var customer1 = new Customer();
5
6
//set all string properties with same value
7
customer1.forEach(function(member){
8
if(member.dataType=='string'){
9
customer1[member.name] = 'my_test_string_value';
10
}
11
});
Copied!
1
{
2
name: string; //name of the property
3
dataType: string; // data type: string, int32, int64, datetime, date, boolean, decimal
4
length:number; //max number character for string dataType
5
required: boolean; //if value is required during add() and update()
6
isPK: boolean; //indicates if the property is primary key - true for property with name DMS_ROWID
7
}
Copied!

DMS_ROWID: string

Description
Example
DMS_ROWID property is the unique identifier of the business object instance and is used as a primary key field in the corresponding record in the mobile database. DMS_ROWID is a string, which contains unique UUID( GUID) value. The value an be either automatically generated by the framework when the BusinessObjectBase.add method is called or manually provided by the developer by using the uuid npm or similar uuid generation algorithm.
1
import { Customer } from '@dms-bo';
2
import * as uuid from 'uuid'
3
...
4
var customer1 = new Customer();
5
await customer1.add();
6
console.log(customer1.DMS_ROWID); // will print the automatically generated primary key
7
8
var customer2 = new Customer();
9
customer2.DMS_ROWID = uuid.uuidv4(); //provide manually generated primary key
10
await customer2.add();
11
console.log(customer2.DMS_ROWID); // will print the manually generated primary key
12
13
//select business object by DMS_ROWID
14
var customer3 = await customer2.query().filter(`DMS_ROWID='${customer2.DMS_ROWID}'`).executeSelect();
15
//customer3 properties will be the same as customer2
Copied!

dontPostToSyncLog: boolean

Description
Example
Property 'dontPostToSyncLog' is false by default and specifies if the sending of the business object instance must be skipped during changes of the instance. Dynamics Mobile framework will automatically generate and send synchronization packet for each business instance when the business object instance add, update and delete methods are called. if property dontPostToSyncLog is set to true, the framework will not send synchronization packet to the backend, which will make so that the change of the business object will not be reflected on the backend.
1
import { Customer } from '@dms-bo';
2
3
4
...
5
var customer1 = new Customer();
6
...
7
await customer1.add(); // this will persist the entity in the local on-device database and will send packet to the backend
8
9
...
10
var customer2 = new Customer();
11
...
12
customer2.dontPostToSyncLog = true;
13
await customer2.add(); // this will persist the entity localy in the on-device database, but will NOT send sychronization packet to the backend
Copied!

state: 0 | 1 | 2 | 3

Description
Example
Property 'state' represent the state of the business object.
    0 - not modified
    1 - created (inserted)
    2 - updated
    3 - deleted
Call to the methods add, update, delete will change the state property accordingly.
1
import { Customer } from '@dms-bo';
2
3
4
...
5
var customer1 = new Customer();
6
console.log(customer1.state); // will print 0
7
...
8
await customer1.add();
9
console.log(customer1.state); // will print 1
10
11
await customer1.update();
12
console.log(customer1.state); // will print 2
13
14
await customer1.delete();
15
console.log(customer1.state); // will print 3
Copied!

static query(): DbQuery<T>

Description
Parameters
Returns
Example
The query method will return generic DbQuery instance bound to the current business object instance. This allows the developer to query the local database.
See DbQuery for more information how to use DbQuery
the method has no parameters
Returns generic instance of DbQuery where the type T is equal to the type of the actual BusinessObjectBase ancestor
1
import { Customer } from '@dms-bo';
2
3
4
...
5
var customer = await Customer.query().filter(`no=1`).executeSelect();
6
if(customer && customer.length>0)
7
console.log(customer[0].no);
Copied!

static livelinkQuery(): LiveLinkQuery<T>

Description
Parameters
Returns
Example
The query method will return generic LiveLinkQuery instance bound to the current business object instance. This allows the developer to query the local database.
See LiveLinkQuery for more information how to use it
Returns generic instance of LiveLinkQuery where the type T is equal to the type of the actual BusinessObjectBase ancestor
1
import { Customer } from '@dms-bo';
2
3
4
...
5
var customer = await Customer.livelinkQuery().filter(`no=1`).executeSelect();
6
if(customer && customer.length>0)
7
console.log(customer[0].no);
Copied!

async add(): Promise<void>

Decription
Parameters
Returns
Example
The method persists the entity by inserting it as new record into the local on-device database. The method will also generate synchronization packet to notify the backend for a change. The method works in offline mode and the sync packet will be sent to Dynamics Mobile Portal and/or ERP asynchronously once a network connection is detected.
the method has no parameters
void
1
import { Customer } from '@dms-bo';
2
3
4
...
5
var customer = new Customer();
6
customer.no = 1;
7
customer.name ='customer1'
8
await customer.add();
Copied!

async update(): Promise<void>

Description
Parameters
Returns
Example
The method persists the entity by updating it into the local on-device database by using the primary key (DMS_ROWID). The method will also generate synchronization packet to notify the backend for a change. The method works in offline mode and the sync packet will be sent to Dynamics Mobile Portal and/or ERP asynchronously once a network connection is detected.
The method has no parameters
void
1
import { Customer } from '@dms-bo';
2
3
4
...
5
//fetch existing customer from the local on-device database
6
var customer = await Customer.query().filter(`DMS_ROWID='xyz-abv-cde-qwe-dfa-ioq'`).executeSelect();
7
if(customer.lenght>0) {
8
//modify the name property in-memory
9
customer.name ='customer1-newname'
10
//persist the change locally and remote
11
await customer.update();
12
}
Copied!

async delete(): Promise<void>

Description
Parameters
Returns
Example
The method deletes the entity from the local on-device database by using the primary key (DMS_ROWID). The method will also generate synchronization packet to notify the backend for a change. The method works in offline mode and the sync packet will be sent to Dynamics Mobile Portal and/or ERP asynchronously once a network connection is detected.
The method has no parameters
void
1
import { Customer } from '@dms-bo';
2
3
4
...
5
//fetch existing customer from the local on-device database
6
var customer = await Customer.query().filter(`DMS_ROWID='xyz-abv-cde-qwe-dfa-ioq'`).executeSelect();
7
if(customer.lenght>0) {
8
//delete the entity locally and remote
9
await customer.delete();
10
}
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 Customer in the Business Object folder
5
6
@View()
7
export class MyView {
8
9
//declare observable variable - supposed to be bi-directionally databound to the corresponding view ( html)
10
public customer: ko.Observable<Customer>;
11
12
constructor(
13
private DocumentSeriesService: DocumentSeriesService,
14
private UserInterfaceService: UserInterfaceService){
15
//create 'empty' instance of the customer and provide it to the observable to make sure it is "connected" to the UI
16
this.customer = ko.observable<Customer>(new Customer());
17
}
18
19
//called to validate the UI form
20
public async validate(){
21
22
//valaidate the user input.
23
//it is supposed that the customer properties are automatically propagated via data-bind
24
25
if(!this.customer().no || !this.customer().name) {
26
return false;
27
}
28
else{
29
return true;
30
}
31
32
}
33
34
//called to persist the UI form
35
public async commit(){
36
//create the customer in the database
37
await this.customer().add();
38
}
Copied!
Last modified 1yr ago