Item
Item represents a data record in DB.
Each item has data structure according to its item type, so all the properties defined in the item type are available in the item data record.
Some properties have dynamic nature and are calculated by the item on access (e.g. expression properties, dynamic default values, etc.).
Some properties are treated as navigation properties (e.g. PickList properties) and are automatically expanded to the referred items.
In addition, child relationships are automatically expanded to collections of items.
Also, there are special properties prefixed by ‘$’, that are available for all items regardless of item type.
Item Properties
$ItemType : ItemType
The item type (reference to ItemType instance).
$Solution : Solution
The solution the item belongs to.
$State : ItemState
The item current state.
$Transitions : LifecycleNextState[]
Available next states the item can transition to.
$Views : ItemViews
Get available read and update views for the item in its current state.
$Owner : Item
Owner item if this item is nested (complex type) or null otherwise.
$OwnerProperty : String?
The property name of this nested item in its owner item.
$RootOwner : Item
Root owner item if this item is nested (complex type) or self otherwise.
$RootParent : Item
The most outer parent item for relationship/link items, otherwise self.
$Original : Item
Original copy of the item before any modifications in the current transaction.
$IsNew : Boolean
Indicates that the item is new and is not committed yet.
$IsModified : Boolean
Indicates that the item has local modifications.
Item Methods
IsItemDeleted() : Boolean
Checks if the item was deleted in the current transaction.
GetPropertyState(fullName, view?, excludeServantKeys = false)
Calculates state expression of the specified property of the item.
GetPropertyState Parameters
fullName : String
Property name (or path for nested).
view? : View
Target view for state expression.
excludeServantKeys? : Boolean
True to exclude all servant keys from property state dictionary (keys prefixed by ‘$’).
CanRead() : Boolean
Checks if the current user has read permission to this item.
CanUpdate() : Boolean
Checks if the current user has update permission to this item.
CanDelete() : Boolean
Checks if the current user has delete permission to this item.
$CanReadRemote() : Boolean
Checks if the current user can read this item remotely (e.g. trhough API).
$CanUpdateRemote() : Boolean
Checks if the current user can update this item remotely (e.g. trhough API).
$CanDeleteRemote() : Boolean
Checks if the current user can delete this item remotely (e.g. trhough API).
IsEmptyComplexItem() : Boolean
Checks if this item is complex item (property type) with all properties set to null.
ItemList
ItemList is a lazy array of items (Item[]).
ItemList has a number of methods to filter, sort and skip items before enumeration.
All operations are lazy, so, for example, Filter method adjusts DB query instead of getting all items and then filtering.
ItemList Methods
IncludeDerived(onlyPolymorphic = false) : ItemList
Include derived items.
IncludeDerived Parameters
onlyPolymorphic? : Boolean
ExcludeDerived() : ItemList
Exclude derived items.
IncludeArchived() : ItemList
Include archived items.
Remote() : ItemList
Include only items accessible remotely.
SkipCache() : ItemList
Sometimes it is needed to skip cache and get items directly from DB.
Filter(query) : []
Filter items by specified criteria.
Filter Parameters
query
Provide string to search by Name, or provide predicate function (e.g. x => x.Index > 1).
RawFilter(query) : []
Filter items by specified criteria in raw search query format.
RawFilter Parameters
query
Provide string to search by Name in the SearchOp format (e.g. “((Name=’X’)&(Value>1))|(Prop=2)”).
RawOptions(options, isAggregation = true, noTypeFilter = false) : ItemList
Adds mongo aggregation pipeline stages to the current request.
See https://www.mongodb.com/docs/manual/core/aggregation-pipeline/
Raw aggregation requests should only be used in read-only requests because they operate on the database directly and thus they do not see item changes in the transaction cache.
Notes:
- Filter is used before RawOptions
- Use $project to remove Id property to avoid reading item by the Id
- Output (projected) properties (currently) should not match the item type properties (or e.g. expression will be calculated instead)
RawOptions Parameters
options
Stages array (added after current stages) or an object with { before, after } array fields.
isAggregation : Boolean = true
False to indicate that the data returned can be treated as item data (useful if there is no $group stage).
noTypeFilter? : Boolean
Optimization to remove filter for ItemTypeId$ (usually/almost never needed).
RawOptions Examples
// Count items by status
$.Solution.ItemType.Items.Filter(x => x.Status != 'Status').RawOptions([
{ $group = { _id = '$Status', count = { $sum = 1 } } },
{ $match = { count = { $gt = 1 } } },
{ $project = { _id = 0, status = '$Status', count = '$count' } },
])
Skip(count) : ItemList
Skip first N items.
Skip Parameters
count : Integer
Take(count) : ItemList
Take first N items.
Take Parameters
count : Integer
Collate(caseInsensitive) : ItemList
Set case insensitive search option.
Collate Parameters
caseInsensitive : Boolean
Sort(args?) : []
Sort items by specified properties.
Sort Parameters
args? : []
Sort Examples
// sort items by Name ascending
$.SomeSolution.SomeType.Items.Sort(true, i => i.Name);
// sort items by Name descending
$.SomeSolution.SomeType.Items.Sort(false, i => i.Name);
// sort items by Name ascending, then by Sequence
$.SomeSolution.SomeType.Items.Sort(true, i => i.Name, true, i => i.Sequence);
Any(predicate) : Boolean
Returns false if predicate is false for all items or there is no items.
Any Parameters
predicate
Provide string to search by Name, or provide predicate function (e.g. x => x.Index > 1).
All(predicate) : Boolean
Returns true if predicate is true for all items or if there is no items.
All Parameters
predicate
Provide string to search by Name, or provide predicate function (e.g. x => x.Index > 1).
First(query?, defValue?) : Item
Filter items by specified criteria and get first one.
First Parameters
query?
Provide string to search by Name, or provide predicate function (e.g. x => x.Index > 1).
defValue? : Item
Default item to return if no any item is found.
IsEmpty() : Boolean
True if there are no items.
Update(properties, skipEvent = false) : ItemList
Update certain properties for all items.
Update Parameters
properties : Dict
skipEvent? : Boolean
Delete() : Long
Delete all items.
ItemState
Represents current state of an item.
ItemState Properties
LifecycleStateId : Integer
IsArchived : Boolean
Indicates that the item is in archived state.
UpdatedOn : DateTime
Last time the item was updated.
UpdatedById : Guid
ID of the user who updated the item last.
UpdatedByUserName : String
Name of the user who updated the item last.
Error : Error
The error occurred during last update operation (if any).
IsLocked : Boolean
Indicates that the item is locked.
LifecycleState : LifecycleState
Current lifecycle state of the item.
IconClass : String
Current lifecycle state icon.
Color : String
Current lifecycle state color.
UpdatedBy : Identity
User who updated the item last.
ItemViews
Item views accessible to the current user in the current item state.
ItemViews Properties
Read : View[]
Accessible views of type Read.
Update : View[]
Accessible views of type Update.
Count : Integer
Number of accessible views of type Read and Update.