Module functions
#
Module specific functions#
addThe 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(Map
orList
record);
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";
#
addTemplateDataThe addTemplateData function creates a new record with given values in the specified module and form.
Syntax:
Module(
moduleName
).addTemplateData(Number
formId,Map
record);
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";
#
updateThe update record function updates a module's records which meet a given criteria.
The criteria is mandatory.
Syntax:
Module(
moduleName
).update(Criteria
criteria,Map
updateRecord);
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";
#
deleteThe delete record function deletes a module's records which meet a given criteria.
The criteria is mandatory.
Syntax:
Module(
moduleName
).delete(Criteria
criteria);
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";
#
fetchThe fetch record function retrieves records from a specified module, when a given criteria is met.
Syntax:
Module(
moduleName
).fetch(Criteria
criteria);
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;
#
exportThe export function retrieves records from a specified module, when a given criteria is met and returns a downloadable file url.
Syntax:
Module(
moduleName
).export(String
viewName,Criteria
criteria);
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 url
#
exportAsFileIdThe export function retrieves records from a specified module, when a given criteria is met and returns a fieldId.
Syntax:
Module(
moduleName
).exportAsFileId(String
viewName,Criteria
criteria);
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; // 54590770
#
asMapThe 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 map
#
getViewCriteriaThe getViewCriteria function retrieves criteria object from a specified module and view name.
Syntax:
Module(
moduleName
).getViewCriteria(String
viewName);
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 object
#
getIdThe 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; // 23979
#
getAllStatesThe 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;
#
addNoteThe 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(Number
recordId,String
note);
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";
#
addAttachmentsThe 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(Number
recordId,Number
fileId);
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; // 23979
#
Module meta functions#
getModuleThe getModule function retrieves module object from a specified module.
Syntax:
new NameSpace("module").getModule(
String
moduleName);
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 object
#
getFieldThe getField function retrieves field object from a specified module and field.
Syntax:
new NameSpace("module").getField(
String
fieldName,String
moduleName);
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 object
#
getEnumFieldValueThe 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(
String
picklist,String
moduleName,Number
Index);
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 Issue
#
Asset specific functions#
getAssetsFromSpaceIdThe getAssetsFromSpaceId function retrieves all assets from a specified space.
Syntax:
new NameSpace("asset").getAssetsFromSpaceId(
Number
spaceId);
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;
#
getAssetCategoryFieldsThe getAssetCategoryFields function retrieves all fields from a specified asset category.
Syntax:
new NameSpace("asset").getAssetCategoryFields(
Number
assetCategoryId);
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;
#
fetchFirstThe fetchFirst record function retrieves the first record from a specified module, when a given criteria is met.
Syntax:
Module(
moduleName
).fetchFirst(Criteria
criteria);
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;