--- alias: user-guide-automation-business-scenarios-building-structure-step-script-lboutilities tags: - automation - connect iot description: "These utility functions provide methods for managing LBO data and related operations" --- # LBOUtilities !!! note This is advanced documentation regarding a scope that can be accessed when executing a step of type `Script`. These methods provide utility functions for interacting with LBO (Lightweight Business Objects) data and performing various operations such as IoT entity retrieval, state model handling, and master data processing. ## iotEnabledEntities === "Declaration" `iotEnabledEntities(fields?: string[]): Promise` === "Description" Retrieves all IoT-enabled entities from the system. Filters the entities based on the presence of `ConnectIoTEnabled` and optionally strips unwanted fields. === "Parameters" - `fields` (optional): An array of field names to retain in the resulting objects. === "Returns" A filtered list of IoT-enabled entities. === "Example" ```json { "name": "Example IoTEnabledEntities", "type": "Script", "resultKey": "iotEnabledEntities", "settings": { "script": [ "(async () => {", " return await this.lboUtilities.iotEnabledEntities();", "})()" ] }, "next": "" } ``` ## entityTypesWithStateModel === "Declaration" `entityTypesWithStateModel(entityTypes?: string[], stripEntity?: boolean, fields?: string[]): Promise` === "Description" Retrieves entity types that have associated state models and optionally filters or strips their properties. === "Parameters" - `entityTypes` (optional): A list of entity type names to filter by. - `stripEntity` (optional): Whether to strip unwanted properties from the result. - `fields` (optional): A list of fields to retain when stripping entities. === "Returns" A list of filtered entity types with state models. === "Example" ```json { "name": "Example EntityTypesWithStateModels", "type": "Script", "resultKey": "iotEntityTypesWithStateModels", "settings": { "script": [ "(async () => {", " const entityTypes = await this.iotUtilities.allEntityTypesFromController(entityInstance);", " const entityTypesWithStateModels = await this.lboUtilities.entityTypesWithStateModel(entityTypes, true);", " if(entityTypesWithStateModels == null || entityTypesWithStateModels.length == 0) {", " throw new Error('No State Model found for Entity Types associated with this controller');", " }", "return entityTypesWithStateModels;", "})()" ] }, "next": "SelectEntityType" } ``` ## entityTypeStateModels === "Declaration" `entityTypeStateModels(entityTypeName: string): Promise>` === "Description" Retrieves state model names and their associated states for a given entity type. === "Parameters" - `entityTypeName`: The name of the entity type to retrieve state models for. === "Returns" A map where keys are state model names, and values are state collections. === "Example" ```json { "name": "Example EntityTypeStateModels", "type": "Script", "resultKey": "iotEntityTypeStateModels", "settings": { "script": [ "(async () => {", " this.answers.stateModels = await this.lboUtilities.entityTypeStateModels(this.answers.iotEntityType.Name);", " const stateModelKeys = Array.from(this.answers.stateModels.keys());", " return this.lboUtilities.convertArrayOfStringsToEnum(stateModelKeys);", "})()" ] }, "next": "CheckStateModels" } ``` ## stripEntity === "Declaration" `stripEntity(obj: any, fields?: string[]): any` === "Description" Strips all properties from an object except for the specified fields. === "Parameters" - `obj`: The object to strip properties from. - `fields` (optional): An array of fields to retain. Defaults to `['$type', 'Name']`. === "Returns" A new object containing only the specified fields. ## convertArrayOfStringsToEnum === "Declaration" `convertArrayOfStringsToEnum(values: string[]): { Id: string, Name: string }[]` === "Description" Converts an array of strings into a format suitable for enumeration. === "Parameters" - `values`: An array of strings to convert. === "Returns" An array of objects where each object has `Id` and `Name` properties. === "Example" ```json { "name": "Example EntityTypeStateModels", "type": "Script", "resultKey": "iotEntityTypeStateModels", "settings": { "script": [ "(async () => {", " this.answers.stateModels = await this.lboUtilities.entityTypeStateModels(this.answers.iotEntityType.Name);", " const stateModelKeys = Array.from(this.answers.stateModels.keys());", " return this.lboUtilities.convertArrayOfStringsToEnum(stateModelKeys);", "})()" ] }, "next": "CheckStateModels" } ``` ## createAndPerformMasterdata === "Declaration" `createAndPerformMasterdata(masterdata: object, masterdataName?: string): Promise` === "Description" Creates a master data package and performs it immediately. === "Parameters" - `masterdata`: The master data object to process. - `masterdataName` (optional): A custom name for the master data package. If not provided, a unique name is generated. === "Returns" `void` ## createMasterdata === "Declaration" `createMasterdata(masterdata: object, masterdataName?: string): Promise` === "Description" Creates a master data package. === "Parameters" - `masterdata`: The master data object to process. - `masterdataName` (optional): A custom name for the master data package. If not provided, a unique name is generated. === "Returns" A `MasterDataPackage` object representing the created package. === "Example" ```json "(async () => {", " return ([await this.lboUtilities.createMasterdata(this.masterdataDirector.getMasterdata())]);", "})()" ``` ## performMasterdata === "Declaration" `performMasterdata(masterdataPackage: MasterDataPackage): Promise` === "Description" Performs a master data package by loading its data into the system. === "Parameters" - `masterdataPackage`: The master data package to perform. === "Returns" `void`