Skip to main content

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(Map or List record);

Parameters:

ParamData typeDescription
record(s)NumberA 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(Number formId, Map record);

Parameters:

ParamData typeDescription
formIdNumberThe Id of the template form.
recordMapA 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(Criteria criteria, Map updateRecord);

Parameters:

ParamData typeDescription
criteriaCriteriaCriteria based on which the records will be updated.
updateRecordMapThe 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(Criteria criteria);

Parameters:

ParamData typeDescription
criteriaCriteriaCriteria 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(Criteria criteria);

Parameters:

ParamData typeDescription
criteriaCriteriaCriteria 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(String viewName, Criteria criteria);

Parameters:

ParamData typeDescription
viewNameStringThe name of view to be exported.
criteriaCriteriaCriteria based on which records will be exported.

Returns: String

Example:

viewName = "open";fileDownloadUrl = Module("workorder").export(viewName, [subject != null]);log fileDownloadUrl; // File download url

exportAsFileId#

The 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:

ParamData typeDescription
viewNameStringThe name of view to be exported.
criteriaCriteriaCriteria based on which records will be exported.

Returns: String

Example:

viewName = "open";fieldId = Module("workorder").exportAsFileId(viewName, [subject != null]);log fieldId; // 54590770

asMap#

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 map

getViewCriteria#

The getViewCriteria function retrieves criteria object from a specified module and view name.

Syntax:

Module( moduleName).getViewCriteria(String viewName);

Parameters:

ParamData typeDescription
viewNameStringView name to get saved criteria object.

Returns: Criteria

Example:

viewCriteria = Module("workorder").getViewCriteria("open");log viewCriteria; // Criteria object

getId#

The getId function takes module name as input and returns the id of that respective module.

Syntax:

Module(moduleName).getId();

Parameters:

ParamData typeDescription
moduleNameStringName of the any module in facilio.

Returns: Number

Example:

moduleId=Module("site").getId();log moduleId; // 23979

getAllStates#

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:

ParamData typeDescription
moduleNameStringName 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(Number recordId, String note);

Parameters:

ParamData typeDescription
moduleNameStringName of the any module in facilio.
recordIdNumberId of that record to which note should be added.
noteStringnote 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(Number recordId, Number fileId);

Parameters:

ParamData typeDescription
moduleNameStringName of the any module in facilio.
recordIdNumberId of that record to which note should be added.
fileIdNumberid 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#

getModule#

The getModule function retrieves module object from a specified module.

Syntax:

new NameSpace("module").getModule(String moduleName);

Parameters:

ParamData typeDescription
moduleNameStringThe 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

getField#

The getField function retrieves field object from a specified module and field.

Syntax:

new NameSpace("module").getField(String fieldName, String moduleName);

Parameters:

ParamData typeDescription
fieldNameStringThe name of the field to be fetched.
moduleNameStringThe 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

getEnumFieldValue#

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(String picklist, String moduleName, Number Index);

Parameters:

ParamData typeDescription
fieldNameStringThe name of the field to be fetched.
moduleNameStringThe 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#

getAssetsFromSpaceId#

The getAssetsFromSpaceId function retrieves all assets from a specified space.

Syntax:

new NameSpace("asset").getAssetsFromSpaceId(Number spaceId);

Parameters:

ParamData typeDescription
spaceIdNumberThe 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(Number assetCategoryId);

Parameters:

ParamData typeDescription
assetCategoryIdNumberThe 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(Criteria criteria);

Parameters:

ParamData typeDescription
criteriaCriteriaCriteria based on which records will be fetched.

Returns: List

Example:

criteria = [name != null];site = Module("site").fetchFirst(criteria);log site;