Module functions
Module specific functions#
add#
The add function creates a new record with given values in the specified module.
NOTE: The added ID will be there along with the map itself.
Syntax:
Module(
moduleName).add(MaporListrecord);
Parameters:
| Param | Data type | Description |
|---|---|---|
| record(s) | Number | A single record map object or list of map records. |
Returns: Void
Example:
site = {};site.name = "HQ at New York";site.description = "Company headquarters";site.totalArea = 200000; // sqft
Module("site").add(site);log site; //{name=HQ at New York, description=Company headquarters, id=7, totalArea=200000}log "site added";addTemplateData#
The addTemplateData function creates a new record with given values in the specified module and form.
Syntax:
Module(
moduleName).addTemplateData(NumberformId,Maprecord);
Parameters:
| Param | Data type | Description |
|---|---|---|
| formId | Number | The Id of the template form. |
| record | Map | A record map object. |
Returns: Void
Example:
formId = 1234;
site = {};site.name = "HQ at New York";site.description = "Company headquarters";site.totalArea = 200000; // sqft
Module("site").addTemplateData(formId, site);log "site added";update#
The update record function updates a module's records which meet a given criteria.
The criteria is mandatory.
Syntax:
Module(
moduleName).update(Criteriacriteria,MapupdateRecord);
Parameters:
| Param | Data type | Description |
|---|---|---|
| criteria | Criteria | Criteria based on which the records will be updated. |
| updateRecord | Map | The update record map object. |
Returns: Number
Example:
siteId = 1;updateSite= {};updateSite.totalArea = 300000; // updates totalArea for the given site
Module("site").update([id == siteId], updateSite);log "site updated";delete#
The delete record function deletes a module's records which meet a given criteria.
The criteria is mandatory.
Syntax:
Module(
moduleName).delete(Criteriacriteria);
Parameters:
| Param | Data type | Description |
|---|---|---|
| criteria | Criteria | Criteria based on which the records will be deleted. |
Returns: Void
Example:
siteId = 1; // the recordId to be deleted
Module("site").delete([id == siteId]);log "site deleted";fetch#
The fetch record function retrieves records from a specified module, when a given criteria is met.
Syntax:
Module(
moduleName).fetch(Criteriacriteria);
Parameters:
| Param | Data type | Description |
|---|---|---|
| criteria | Criteria | Criteria based on which records will be fetched. |
Returns: List
Example:
sites = Module("site").fetch([name != null]);log sites;export#
The export function retrieves records from a specified module, when a given criteria is met and returns a downloadable file url.
Syntax:
Module(
moduleName).export(StringviewName,Criteriacriteria);
Parameters:
| Param | Data type | Description |
|---|---|---|
| viewName | String | The name of view to be exported. |
| criteria | Criteria | Criteria based on which records will be exported. |
Returns: String
Example:
viewName = "open";fileDownloadUrl = Module("workorder").export(viewName, [subject != null]);log fileDownloadUrl; // File download urlexportAsFileId#
The export function retrieves records from a specified module, when a given criteria is met and returns a fieldId.
Syntax:
Module(
moduleName).exportAsFileId(StringviewName,Criteriacriteria);
Parameters:
| Param | Data type | Description |
|---|---|---|
| viewName | String | The name of view to be exported. |
| criteria | Criteria | Criteria based on which records will be exported. |
Returns: String
Example:
viewName = "open";fieldId = Module("workorder").exportAsFileId(viewName, [subject != null]);log fieldId; // 54590770asMap#
The asMap function retrieves module information as map object from a specified module.
Syntax:
Module(
moduleName).asMap();
Returns: Map
Example:
moduleMap = Module("site").asMap();log moduleMap; // Module object as mapgetViewCriteria#
The getViewCriteria function retrieves criteria object from a specified module and view name.
Syntax:
Module(
moduleName).getViewCriteria(StringviewName);
Parameters:
| Param | Data type | Description |
|---|---|---|
| viewName | String | View name to get saved criteria object. |
Returns: Criteria
Example:
viewCriteria = Module("workorder").getViewCriteria("open");log viewCriteria; // Criteria objectgetId#
The getId function takes module name as input and returns the id of that respective module.
Syntax:
Module(
moduleName).getId();
Parameters:
| Param | Data type | Description |
|---|---|---|
| moduleName | String | Name of the any module in facilio. |
Returns: Number
Example:
moduleId=Module("site").getId();log moduleId; // 23979getAllStates#
The getAllStates function takes module name as input and returns the available states for that module.The current status of each values in the module is referred to states(States refer to active, inactive, retired, expired etc).
Syntax:
Module(
moduleName).getAllStates();
Parameters:
| Param | Data type | Description |
|---|---|---|
| moduleName | String | Name of the any module in facilio. |
Returns: List Map
Example:
moduleId=Module("asset").getAllStates();log moduleId;addNote#
The addNote function takes module name, id of the record in that module and note to be added as input and returns the id of that respective module.
Syntax:
Module(
moduleName).addNote(NumberrecordId,Stringnote);
Parameters:
| Param | Data type | Description |
|---|---|---|
| moduleName | String | Name of the any module in facilio. |
| recordId | Number | Id of that record to which note should be added. |
| note | String | note to be added. |
Returns: Void
Example:
recordId = 1362260;note= "Testing";Module("site").addNote(recordId,note);log "Note updated";addAttachments#
The addAttachments function takes module name, id of the record in that module and id of the file to be added as input and returns the uploded file id of that respective module.
Syntax:
Module(
moduleName).addAttachments(NumberrecordId,NumberfileId);
Parameters:
| Param | Data type | Description |
|---|---|---|
| moduleName | String | Name of the any module in facilio. |
| recordId | Number | Id of that record to which note should be added. |
| fileId | Number | id of the file to be added to the record of the given module. |
Returns: Number
Example:
moduleId=Module("site").addAttachments();log moduleId; // 23979Module meta functions#
getModule#
The getModule function retrieves module object from a specified module.
Syntax:
new NameSpace("module").getModule(
StringmoduleName);
Parameters:
| Param | Data type | Description |
|---|---|---|
| moduleName | String | The name of the module to be fetched. |
Returns: Module
Example:
workorder = new NameSpace("module").getModule("workorder");log workorder;
log workorder.asMap(); // convert module object to map objectgetField#
The getField function retrieves field object from a specified module and field.
Syntax:
new NameSpace("module").getField(
StringfieldName,StringmoduleName);
Parameters:
| Param | Data type | Description |
|---|---|---|
| fieldName | String | The name of the field to be fetched. |
| moduleName | String | The module name of the field to be fixed. |
Returns: Field
Example:
subject = new NameSpace("module").getField("subject", "workorder");log subject;
log subject.asMap(); // convert field object to map objectgetEnumFieldValue#
The getEnumFieldValue function retrieves field value from a specified module and picklist field name and its index. Note it wil not retrieve lookup field values.
Syntax:
new NameSpace("module").getEnumFieldValue(
Stringpicklist,StringmoduleName,NumberIndex);
Parameters:
| Param | Data type | Description |
|---|---|---|
| fieldName | String | The name of the field to be fetched. |
| moduleName | String | The module name of the field to be fixed. |
Returns: Field
Example:
subject = new NameSpace("module").getEnumFieldValue("picklist_1", "workorder", 1);log subject; // Product IssueAsset specific functions#
getAssetsFromSpaceId#
The getAssetsFromSpaceId function retrieves all assets from a specified space.
Syntax:
new NameSpace("asset").getAssetsFromSpaceId(
NumberspaceId);
Parameters:
| Param | Data type | Description |
|---|---|---|
| spaceId | Number | The spaceId to fetch asset list. |
Returns: List
Example:
spaceId = 1; // meeting roomassets = new NameSpace("asset").getAssetsFromSpaceId(spaceId);log assets;getAssetCategoryFields#
The getAssetCategoryFields function retrieves all fields from a specified asset category.
Syntax:
new NameSpace("asset").getAssetCategoryFields(
NumberassetCategoryId);
Parameters:
| Param | Data type | Description |
|---|---|---|
| assetCategoryId | Number | The asset category id to fetch the field list. |
Returns: List
Example:
assetCategoryId = 1; // ChillerchillerFields = new NameSpace("asset").getAssetCategoryFields(assetCategoryId);log chillerFields;fetchFirst#
The fetchFirst record function retrieves the first record from a specified module, when a given criteria is met.
Syntax:
Module(
moduleName).fetchFirst(Criteriacriteria);
Parameters:
| Param | Data type | Description |
|---|---|---|
| criteria | Criteria | Criteria based on which records will be fetched. |
Returns: List
Example:
criteria = [name != null];site = Module("site").fetchFirst(criteria);log site;