Code generators

focus on tasks that matters

Overview

Dynamics Mobile CLI provides code generation tool, allowing the developer to quickly generate source code for specific purposes based on predefined templates.

It allows the developer to automate frequent and boring task like creating a new business object definition to communicate with remote system or create a new view, task and others.

How it works

Using the code generators is easy as running a command from the terminal within the root directory of your project.

Let's assume we have the following folder structure

-apps
+ myApp1
- myApp2
- ...
...
- src
+ Business Objects
+ Views
+ Tasks

So, we have our app called myApp2 and we want to generate a new "empty" business object for our app. We need to open terminal (command prompt) and execute the following commands

#go to the apps directory
$user1@yyyyy ~
$ cd apps
#go to myApps2 directory
$user1@yyy ~/apps
$ cd myApp2
#using the generate command with --template parameter to generate
#our business object with name Customer
$user1@yyy ~/apps
$ dms generate --template entity -name Customer
------------------------------------
| Dynamics Mobile |
| App Framework v.0.39.640 |
| 2009-2020 All rights reserved |
| www.dynamicsmobile.com |
------------------------------------
Generation started...
Generating entity Customer ...
Dont forget to run 'npm run genbo' command from terminal
$user1@yyy ~/apps
$

The result of the command is a new file Customer.bo.json in our Business Object folder

-apps
+ myApp1
- myApp2
- ...
...
- src
+ Business Objects
- Customer.bo.json
+ Views
+ Tasks

We may now open the newly created file and see the content:

{
"Customer": {
"name": "Customer",
"label": "Customer",
"pluralLabel": "Customers",
"pageSize": 500,
"searching": true,
"properties": {
"DMS_ROWID": {
"type": "Binary",
"isIdentity": true,
"isPK": true,
"label": "Id",
"sorting": false,
"searching": false,
"uiType": "Default"
}
},
"views": {
"list": {
"properties": [
{
"name": "DMS_ROWID"
}
]
},
"default": {
"properties": [
{
"name": "DMS_ROWID"
}
]
}
}
}
}

So, we have a newly generated skeleton for our business object , which we can augment by adding more properties

Templates

Dynamics Mobile SDK comes with a set of built-in code generators or so called "templates". Following list of built-in templates with instructions how to use them

template: Entity

The Entity template generates a business object definition skeleton. The "skeleton" definition contains basic business object attributes like name and properties and the default primary key property DMS_ROWID.

$ dms generate --template entity -name Customer

The upper command will generate a skeleton business object definition in ./src/Business Object folder.

template: Service Entity

The Service Entity template generates a complete business object definition from a remote service like Microsoft Dynamics 365 Business Central , Microsoft Dynamics 365 for Operations others. It is required that the application area where we develop our application to have a defined livelinkservice and we need to know its name.

Once we have these , we can execute the following command from the app's directory:

$ dms generate --template service-entity --name Company --service myBCService
------------------------------------
| Dynamics Mobile |
| App Framework v.0.39.640 |
| 2009-2020 All rights reserved |
| www.dynamicsmobile.com |
------------------------------------
Generation started...
Generating service-entity Company...
Using template 'service', remote service 'myBCService', app SLA
Don't forget to run 'npm run genbo' command from terminal
Generation completed
$

And we now have a new Company business object file created in ./src/Business Objects directory. We can use this object now to directly query Company records from the remote service by using LiveLinkQuery and create, update and delete records.

Parameters

Parameter

Value

Notes

template

service-entity

name

string value (letters and digits only, no spaces and special characters)

The name of the entity to look for in the remote service

service

string value (letters and digits only, no spaces and special characters)

The name of the service as it is defined in the user's role settings in the apparea

overwrite

true | false

Overwrites the existing local business object file, if it exists

See also