Base class and the default implementation for the DataContextItem object, other implementations (sub-classes) can be registered as well with higher priorities to take over for this particular class.

Hierarchy

  • DataContextItem

    Constructors

    Properties

    AdditionalDescription?: string

    Additional Description has any other information that might be useful for someone (or an LLM) intepreting the contents of this data item

    CodeName?: string

    CodeName - property that is generated by the system to be used as a unique name programmatically within a given data context. This is not used in the API, but can be used in the UI or other places where a unique name is needed for the data context item. This is generated by the system and is not set by the user.

    DataContextItemID?: string

    This field can be used at run time to stash the record ID in the database of the Data Context Item, if it was already saved. For items that haven't/won't be saved, this property can be ignored.

    DataLoaded: boolean = false

    This property is set to true if the data has been loaded for this DataContextItem, and false if it has not been loaded or if there was an error loading the data.

    DataLoadingError?: string

    This property contains an error message if there was an error loading the data for this DataContextItem. If there was no error, this property will be null;

    Entity?: EntityInfo

    Entity - the object that contains metadata for the entity being used, only populated if the type is 'full_entity' or 'view' - also this is NOT to be sent to/from the API server, it is a placeholder that can be used within a given tier like in the MJAPI server or in the UI.

    EntityID?: string

    EntityID - the ID of the entity in the system, only used if type = 'full_entity', 'view', or 'single_record' --- for type of 'query' or 'sql' this property is not used as results can come from any number of entities in combination

    EntityName?: string

    The name of the entity in the system, only used if type = 'full_entity', 'view', or 'single_record' --- for type of 'query' or 'sql' this property is not used as results can come from any number of entities in combination

    Fields: DataContextFieldInfo[] = []
    QueryID?: string

    QueryID - the ID of the query in the system, only used if type = 'query'

    RecordID: string

    The primary key of the single record in the system, only used if type = 'single_record'. If the Entity has a composite key, this will be a command separated list of the primary key values in order of their definition in the entity.

    RecordName: string

    The name of the view, query, or entity in the system. Not used with type='single_record' or type='sql'

    SQL?: string

    SQL - the SQL statement to execute, only used if type = 'sql'

    SingleRecord?: BaseEntity<unknown>

    SingleRecord - the object instantiated that contains the data for the single record being used - only populated if the type is 'single_record' - also this is NOT to be sent to/from the API server, it is a placeholder that can be used in a given tier

    Type: "view" | "query" | "full_entity" | "sql" | "single_record"

    The type of the item, either "view", "query", "full_entity", or "sql", or "single_record"

    ViewEntity - the object instantiated that contains the metadata for the UserView being used - only populated if the type is 'view', also this is NOT to be sent to/from the API server, it is a placeholder that can be used within a given tier like in the MJAPI server or in the UI.

    ViewID?: string

    ViewID - the ID of the view in the system, only used if type = 'view'

    _Data?: any[]

    Accessors

    • get Data(): any[]
    • This property contains the loaded data for the DataContextItem, if it was loaded successfully. The data will be in the form of an array of objects, where each object is a row of data.

      Returns any[]

    • set Data(value): void
    • Parameters

      • value: any[]

      Returns void

    • get Description(): string
    • Generated description of the item which is dependent on the type of the item

      Returns string

    Methods

    • This method should only be called after this Item has been fully initialized. That can be done by calling LoadMetadata() on the DataContext object, or by calling the static methods FromViewEntity, FromSingleRecord, FromQuery, or FromFullEntity, or finally by manually setting the individual properties of the DataContextItem object. A helper method, Load() at the DataContext level can be called to load the metadata and then all of the data for all items in the data context at once.

      Parameters

      • dataSource: any

        the data source to use to execute the SQL statement - specified as an any type to allow for any type of data source to be used, but the actual implementation will be specific to the server side only. For client side use of this method, you can leave this as undefined and the Load will work so long as the Data Context Items you are loading are NOT of type 'sql'

      • forceRefresh: boolean = false

        (defaults to false) if true, the data will be reloaded from the data source even if it is already loaded, if false, the data will only be loaded if it hasn't already been loaded

      • loadRelatedDataOnSingleRecords: boolean = false

        (defaults to false) if true, related entity data will be loaded for single record items, if false, related entity data will not be loaded for single record items

      • maxRecordsPerRelationship: number = 0

        (defaults to 0) for the LoadData() portion of this routine --- if this param is set to a value greater than 0, the maximum number of records to load for each relationship will be limited to this value. Applies to single_record items only.

      • Optional contextUser: UserInfo

        the user that is requesting the data context (only required on server side operations, or if you want a different user's permissions to be used for the data context load)

      Returns Promise<boolean>

    • If you already have the data loaded for an individual Data Context Item, you can load it into the object using this method. It is your responsibility to ensure that the data object is in the correct format for the DataContextItem object. This method will not validate the data object, it will just load it into the Data property of the object.

      Parameters

      • data: any[]

      Returns boolean

    • Loads the data context item data from a full entity (meaning all rows in a given entity). This method is called by the LoadData method if the type of the data context item is 'full_entity'

      Parameters

      Returns Promise<boolean>

    • Loads the data context item data from a query. This method is called by the LoadData method if the type of the data context item is 'query'

      Parameters

      Returns Promise<boolean>

    • Overrideable in sub-classes, the default implementation will throw an error because we don't have the ability to execute random SQL on the client side

      Parameters

      • dataSource: any

        the data source to use to execute the SQL statement - specified as an any type to allow for any type of data source to be used, but the actual implementation will be specific to the server side only

      • contextUser: UserInfo

        the user that is requesting the data context (only required on server side operations, or if you want a different user's permissions to be used for the data context load)

      Returns Promise<boolean>

    • Loads the data context item data from a query. This method is called by the LoadData method if the type of the data context item is 'query'

      Parameters

      • contextUser: UserInfo
      • includeRelatedEntityData: boolean
      • maxRecordsPerRelationship: number

      Returns Promise<boolean>

    • Loads the data context item data from a view. This method is called by the LoadData method if the type of the data context item is 'view'

      Parameters

      Returns Promise<boolean>

    • Validates that the Data property is set. Valid states include a zero length array, or an array with one or more elements. If the Data property is not set, this method will return false

      Parameters

      • ignoreFailedLoad: boolean = false

        if true, we will not validate the data if the DataLoaded property is false, if false, we will validate the data regardless of the DataLoaded property

      Returns boolean

    • Creates a new DataContextItem object from a raw data object. This method will return a new DataContextItem object if the raw data was successfully converted, and will return null if the raw data was not successfully converted.

      Parameters

      • rawItem: any

      Returns DataContextItem