> For the complete documentation index, see [llms.txt](https://docs.fieldmotion.com/fieldmotion-api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fieldmotion.com/fieldmotion-api-docs/reporttemplate/_createdata.md).

# \_createData

Creates a new Report Template.

### Parameters

#### name

The name to be assigned to the Report Template.

#### description

The description for the new Report Template.

#### mainTable

The sort of area which the Report Template will be on, a list of what this parameter can be set to below:

* account
* accountCategory
* asset
* assetType
* commonList
* contract
* contractType
* customer
* customerAssetLocation
* customerType
* department
* form
* file
* goodReceived
* goodReturned
* invoice
* job
* jobRecurring
* jobType
* layoutGroup
* location
* log
* marketingSource
* marketingExpense
* opportunity
* opportunityStatus
* priceBand
* purchaseOrder
* quote
* referral
* reportTemplate
* requisitionOrder
* scheduleOfRate
* stock
* stockBundle
* stockCategory
* stockHistory
* stockInventory
* stockSupplier
* supplier
* task
* taskType
* user
* userRole
* vehicle

### Examples

General example of making a new Report Template:

```
FM_api('ReportTemplate_createData',[
    'name'=>'Test Report Template Three',
    'description'=>'stock test',
    'mainTable'=>'stock'
]);
```

If you specifically want a Report Template referring to Completed Jobs:

```
FM_api('ReportTemplate_createData',[
    'name'=>'Test Template Two',
    'description'=>'test desc',
    'mainTable'=>'job',
    'meta'=>['specialID'=>'jobCompleted'],
    'legend'=>[
                  [
                     'id'=>'summary1',
                     'field'=>'summary',
                     'table'=>'job',
                     'type'=>'special',
                     'name'=>'Due',
                     'option'=>[
                              'aggregate'=>'count',
                              'defaultChart'=>'line',
                              'filter'=>[
                                          [
                                             'andOr'=>'and',
                                             'condition'=>'notEqual',
                                             'id'=>'job_isComplete',
                                             'value'=>['5'],
                                             'valueType'=>'0'
                                          ],
                                          [
                                             'andOr'=>'and',
                                             'condition'=>'equal',
                                             'id'=>'job_deleted',
                                             'value'=>'0',
                                             'valueType'=>'0'
                                          ]
                                       ]
                              ]
                  ],
                  [
                     'id'=>'summary2',
                     'field'=>'summary',
                     'name'=>'On time',
                     'option'=>[
                              'aggregate'=>'count',
                              'defaultChart'=>'line',
                              'filter'=>[
                                          [
                                             'andOr'=>'and',
                                             'condition'=>'equal',
                                             'id'=>'job_isComplete',
                                             'value'=>['1','2','3','4'],
                                             'valueType'=>'0'
                                          ],
                                          [
                                             'andOr'=>'and',
                                             'condition'=>'equal',
                                             'id'=>'job_deleted',
                                             'value'=>'0',
                                             'valueType'=>'0'
                                          ],
                                          [
                                             'andOr'=>'and',
                                             'condition'=>'greaterThan',
                                             'id'=>'job_dueDate',
                                             'value'=>['id'=>'dayAdd',
                                                      'params'=>['dateCompleted','8']
                                             ],
                                             'valueType'=>'0'
                                          ]
                                       ]
                              ],
                     'table'=>'job',
                     'type'=>'special'
                  ],
                  [
                     'id'=>'summary3',
                     'field'=>'summary',
                     'name'=>'Late',
                     'option'=>[
                              'aggregate'=>'count',
                              'defaultChart'=>'line',
                              'filter'=>[
                                          [
                                             'andOr'=>'and',
                                             'condition'=>'equal',
                                             'id'=>'job_isComplete',
                                             'value'=>['1','2','3','4'],
                                             'valueType'=>'0'
                                          ],
                                          [
                                             'andOr'=>'and',
                                             'condition'=>'equal',
                                             'id'=>'job_deleted',
                                             'value'=>'0',
                                             'valueType'=>'0'
                                          ],
                                          [
                                             'andOr'=>'and',
                                             'condition'=>'greaterThan',
                                             'id'=>'job_dueDate',
                                             'value'=>['id'=>'dayAdd',
                                                      'params'=>['dateCompleted','4']
                                             ],
                                             'valueType'=>'1'
                                          ]
                                       ]
                              ],
                     'table'=>'job',
                     'type'=>'special'
                  ],
                  [
                     'id'=>'summary4',
                     'field'=>'summary',
                     'name'=>'Incomplete',
                     'option'=>[
                              'aggregate'=>'count',
                              'defaultChart'=>'line',
                              'filter'=>[
                                          [
                                             'andOr'=>'and',
                                             'condition'=>'equal',
                                             'id'=>'job_isComplete',
                                             'value'=>['0'],
                                             'valueType'=>'0'
                                          ],
                                          [
                                             'andOr'=>'and',
                                             'condition'=>'equal',
                                             'id'=>'job_deleted',
                                             'value'=>'0',
                                             'valueType'=>'0'
                                          ]
                                       ]
                              ],
                     'table'=>'job',
                     'type'=>'special'
                  ],
                  [
                     'id'=>'formula1',
                     'field'=>'formula',
                     'name'=>'Percentage',
                     'option'=>[
                              'defaultChart'=>'bar',
                              'formula'=>['(','summary2','/','summary1',')','*','100']
                              ],
                     'table'=>'job',
                     'type'=>'special'
                  ]
    ],
    'groupField'=>[
                   [
                   'id'=>'dueDate1',
                   'field'=>'dueDate',
                   'table'=>'job',
                   'type'=>'datetime'
                ]
          ]
    ]
);
```

### Results

#### On Success

```
"{"ok":1,"id":"60001"}"
```

#### On Failure

If the "name" parameter is not set:

```
{"error":"missing or invalid parameter: name"}
```
