Comment on page
BusinessObjectBase
BusinessObjectBase TypeScript Class Reference
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 |
string | |
string | |
string | |
string | |
string | |
string | |
boolean | |
number |
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.
import { Customer } from '@dms-bo';
...
var customer = new Customer();
Devices: All
Clouds: All
📳
☁
📳
🌐
Description
Example
Property 'appCode' contains the unique of the application where the business object was generated.
import { Customer } from '@dms-bo';
...
console.log(`current app code is ${Customer.appCode}`)
Description
Example
Property 'boName' contains the name of the business object
import { Customer } from '@dms-bo';
...
console.log(`current business object name is ${Customer.boName}`)
//prints out: Customer
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.
import { Customer } from '@dms-bo';
...
console.log(`current business object sync name is ${Customer.boSyncName}`)
//prints out: Customer
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.
import { Customer } from '@dms-bo';
import { SqlQueryService } from '@dms';
...
let sqlStatement = `select * from ${Customer.boTableName}`;
let records = await this.SqlQueryService.execute();
Description
Example
BusinessObjectMember
the property contains metadata for the properties of the business object as they are defined in the business object JSON definition.
import { Customer } from '@dms-bo';
import * as uuid from 'uuid'
...
var customer1 = new Customer();
//set all string properties with same value
customer1.forEach(function(member){
if(member.dataType=='string'){
customer1[member.name] = 'my_test_string_value';
}
});
{
name: string; //name of the property
dataType: string; // data type: string, int32, int64, datetime, date, boolean, decimal
length:number; //max number character for string dataType
required: boolean; //if value is required during add() and update()
isPK: boolean; //indicates if the property is primary key - true for property with name DMS_ROWID
}
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.
import { Customer } from '@dms-bo';
import * as uuid from 'uuid'
...
var customer1 = new Customer();
await customer1.add();
console.log(customer1.DMS_ROWID); // will print the automatically generated primary key
var customer2 = new Customer();
customer2.DMS_ROWID = uuid.uuidv4(); //provide manually generated primary key
await customer2.add();
console.log(customer2.DMS_ROWID); // will print the manually generated primary key
//select business object by DMS_ROWID
var customer3 = await customer2.query().filter(`DMS_ROWID='${customer2.DMS_ROWID}'`).executeSelect();
//customer3 properties will be the same as customer2
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.
import { Customer } from '@dms-bo';
...
var customer1 = new Customer();
...
await customer1.add(); // this will persist the entity in the local on-device database and will send packet to the backend
...
var customer2 = new Customer();
...
customer2.dontPostToSyncLog = true;
await customer2.add(); // this will persist the entity localy in the on-device database, but will NOT send sychronization packet to the backend
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.
import { Customer } from '@dms-bo';
...
var customer1 = new Customer();
console.log(customer1.state); // will print 0
...
await customer1.add();
console.log(customer1.state); // will print 1
await customer1.update();
console.log(customer1.state); // will print 2
await customer1.delete();
console.log(customer1.state); // will print 3
Description
Parameters
Returns
Example
the method has no parameters
Returns generic instance of DbQuery where the type T is equal to the type of the actual BusinessObjectBase ancestor
import { Customer } from '@dms-bo';
...
var customer = await Customer.query().filter(`no=1`).executeSelect();
if(customer && customer.length>0)
console.log(customer[0].no);
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.
Returns generic instance of LiveLinkQuery where the type T is equal to the type of the actual BusinessObjectBase ancestor
import { Customer } from '@dms-bo';
...
var customer = await Customer.livelinkQuery().filter(`no=1`).executeSelect();
if(customer && customer.length>0)
console.log(customer[0].no);
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
import { Customer } from '@dms-bo';
...
var customer = new Customer();
customer.no = 1;
customer.name ='customer1'
await customer.add();
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
import { Customer } from '@dms-bo';
...
//fetch existing customer from the local on-device database
var customer = await Customer.query().filter(`DMS_ROWID='xyz-abv-cde-qwe-dfa-ioq'`).executeSelect();
if(customer.lenght>0) {
//modify the name property in-memory
customer.name ='customer1-newname'
//persist the change locally and remote
await customer.update();
}
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
import { Customer } from '@dms-bo';
...
//fetch existing customer from the local on-device database
var customer = await Customer.query().filter(`DMS_ROWID='xyz-abv-cde-qwe-dfa-ioq'`).executeSelect();
if(customer.lenght>0) {
//delete the entity locally and remote
await customer.delete();
}
import { View, DocumentSeriesService, UserInterfaceService } from '@dms';
import { Invoice } from '@dms-bo';
// it is supposed that there is defined business object Customer in the Business Object folder
@View()
export class MyView {
//declare observable variable - supposed to be bi-directionally databound to the corresponding view ( html)
public customer: ko.Observable<Customer>;
constructor(
private DocumentSeriesService: DocumentSeriesService,
private UserInterfaceService: UserInterfaceService){
//create 'empty' instance of the customer and provide it to the observable to make sure it is "connected" to the UI
this.customer = ko.observable<Customer>(new Customer());
}
//called to validate the UI form
public async validate(){
//valaidate the user input.
//it is supposed that the customer properties are automatically propagated via data-bind
if(!this.customer().no || !this.customer().name) {
return false;
}
else{
return true;
}
}
//called to persist the UI form
public async commit(){
//create the customer in the database
await this.customer().add();
}
Last modified 3yr ago