IafScriptEngine
Use the IafScriptEngine higher-level API to write scripts on the platform by using utility functions and calling platform APIs.
addDatasource
Creates an orchestrator.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Add an Orchestrator object. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise<Orchestrator> - A promise with the created Orchestrator object
let req = {
"_name": "Rest Connector",
"_description": "Rest Connector Calls",
"_namespaces": [
"$current_project._namespaces"
],
"_userType": "xlsx_import",
"_params": {
"tasks": [
{
"_orchcomp": "rest_connector",
"_name": "Get telemetry data from data aggregation platform",
"_sequenceno": 1,
"_actualparams": {
"_url": "http://telemetry.com/api",
"_auth": {
"_type": "BasicAuth",
“_params”: {
“_username”: proj_1.username,
“_password”: proj_1.username.pwd
}
},
"to": "json"
},
{
"_orchcomp": "default_script_target",
"_name": "Store telemetry data in the item service",
"_sequenceno": 2,
"_actualparams": {
"userType": "iaf_telem_store",
"_scriptName": "storeTelem",
}
}
]
}
};
let orchestrator = await IafScriptEngine.addDatasource(req);
addNamespaceToCtx
Add a namespace to the Ctx, which is the context that you can refer to in other methods.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with a "_namespaces" property. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Ctx - Context storage
let req = {
"_namespaces": ["1_pzOxaMwR", "5_ly2xbPwD", "7_hsLqaCwP"]
};
IafScriptEngine.addNamespaceToCtx(req);
addRelatedCollections
Adds related collections to a named composite item in the item service.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with "namedCompositeItemId" and "relatedCollections" properties and values. You can also add optional "options", "options.project", "options.sort", "options.page" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
relatedCollection - The added related collections
let req = {
"namedCompositeItemId": "5dcbbd24f16c872134947df2",
"relatedCollections": [
{_userItemId: '5dcbbd24f16c872134947df2'},
{_userItemId: '5dcab6acfa877736bb1c5311'},
{_userItemId: '9puyc6bdga576731fc1c8317'}
]
}
let updatedColl = await IafScriptEngine.addRelatedCollections(req);
attachItemsAsRelated
Creates relationships between child related items and parent related items when you pass parent and child arrays of the same length.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | Pass a JSON object with "parentItems" and "relatedItems" fields. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
createCollection
Creates a collection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | NamedUserItem | Pass a NamedUserItem object with the properties you want to define the collection. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
NamedUserItem - The created collection
let req = {
"_shortName": "example_col",
"_itemClass": “NamedUserCollection”,
"_userType":"example_colection",
"_namespace": ["3_jtOxaGwR"]
};
let collection = await IafScriptEngine.createCollection(req);
createFileCollection
Creates a named file collection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | NamedUserItem | Pass a NamedUserItem object with the properties you want to define the file collection. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
NamedUserItem - The created collection
let req = {
"_shortName": "example_file_col",
"_itemClass": “NamedFileCollection”,
"_userType":"example_file_colection",
"_namespace": ["6_jkOloLGwR"]
};
let fileColl = await IafScriptEngine.createFileCollection(req);
createIndex
Creates a database index for a named user item.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | Index | Pass an Index object with the collection's "_id" property and your database index options. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise<Page<JSON>> - The MongoDB indexes for the collection
let req = {
"_id": "5cee7fee6505d6286dbca469",
"indexDefs": [
{
"key": {
"name": "text",
"fileAttributes.name": "text",
"fileAttributes.description": "text",
"fileAttributes.documentType": "text",
"fileAttributes.iputAssetType": "text",
"fileAttributes.levelsAndLocations": "text"
},
"options": {
"name": "text_search_index",
"default_language": "english"
}
}
]
}
let index = await IafScriptEngine.createIndex(req);
createItems
Creates related items for a user item in the item service.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | Pass a JSON object with "items" and "userItemId" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
RelatedItem - The created related items
let args = {
"items":[{
"source_index": "accounts-4"
}] ,
"_userItemId": "5dcbbd24f16c872134947df2"
};
let items = await createItems(args);
createItemsAsRelatedBulk
Takes an array of related items and creates a relationship between them and one parent related item.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSONObject | Pass a JSON object with "items", "parentUserItemId", and "_userItemId" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
JSON - Returns a bulk response the list of related items with a "_createdCount" parameter with the number of created related items.
createItemsBulk
Creates related items in bulk.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | Pass a JSON object with the two following properties: "items" and "_userItemId". |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
JSON - A bulk JSON response with "_createdCount" and "_uris" properties for each related item
let args = {
"items": [
{"_userType": "hvac_equipment", "name": "condensing_unit"},
{"_userType": "hvac_equipment", "name": "air_handler"},
{"_userType": "hvac_equipment", "name": "air_conditioner"}
],
};
"_userItemId": "5dcab6acfa877736bb1c5311"
};
let relatedItems = await IafScriptEngine.createItemsBulk(args);
createNamedCompositeItem
Creates a named composite item with related collections.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with a "relatedCollections" property. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
NamedUserItem - The created named composite item
let req = {
"relatedCollections": [
{"_userItemId": "5dcbbd24f16c872134947df2"},
{"_userItemId": "5dcab6acfa877736bb1c5311"},
{"_userItemId": "9puyc6bdga576731fc1c8317"}
]
};
let compositeItem = await IafScriptEngine.createNamedCompositeItem(req)
createNamedUserItemVersion
Creates a named user item version.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with a "namedUserItemId" property. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
NamedUserItemVersion - The created named user item version.
let req = {
"namedUserItemId": "5dcbbd24f16c872134947df2",
};
let itemVersion = await IafScriptEngine.createNamedUserItemVersion(req);
createOrchestratorSchedule
Creates an orchestrator schedule.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSONObject | Pass an object with the OrchestratorSchedule properties and values you want to define the orchestrator schedule. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
let req = {
"next_scheduled_time": "1606890210090",
"runinterval": "* * 30"
};
let orchSchedule = await IafScriptEngine.createOrchestratorSchedule(req);
createOrRecreateCollection
Creates a collection or overwrites an existing collection that has the same NamedUserItem criteria.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | NamedUserItem | Pass a NamedUserItem JSON object with the properties you want to define the collection. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
NamedUserItem - The created collection
let req = {
"_shortName": "example_col",
"_itemClass": “NamedUserCollection”,
"_userType":"example_colection",
"_namespace": ["3_jtOxaGwR"]
};
let collection = await IafScriptEngine.createOrRecreateCollection(req);
createOrRecreateIndex
Creates an index for a named user collection, or overwrites the existing index if it has the same "_name" property.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | Index | Pass an Index object with the collection's "_id" property and your database index options. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise<Page<JSON>> - The database indexes for the collection
let req = {
"_id": "5cee7fee6505d6286dbca469",
"indexDefs": [
{
"key": {
"name": "text",
"fileAttributes.name": "text",
"fileAttributes.description": "text",
"fileAttributes.documentType": "text",
"fileAttributes.iputAssetType": "text",
"fileAttributes.levelsAndLocations": "text"
},
"options": {
"name": "text_search_index",
"default_language": "english"
}
}
]
};
let index = await IafScriptEngine.createIndex(req);
createRelations
Creates parent-child relations between parent items in one collection and child items in the same or another collection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | Pass a JSON object with "parentUserItemId", "_userItemId", and "relations" properties. For the "parentUserItemId" property, add the parent user item id as its value. For the "_userItemId" property, add the named user item id as its value. For the "relations" property, add an array of Relationship objects you want to create. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise<String> - ok: 204 response
let args = {
"parentUserItemId": 5ac195d1-4c24-40a3-a2d4-32573ed74217,
"_userItemId": 75b2a3d6-a3e8-498d-99dc-23538bc9a389,
"relations": {
parentItem: {_id: 5fr345r1-4e24-40z3-l2dk-34554ed36789},
relatedItems: [{_id: 7ac887d1-2c88-45a8-3274-73785iu75886}, {_id: 4oi769d7-7l58-28i6-h2d7-85648ty87965}]
}
};
let relations = await IafScriptEngine.createRelations(args);
deleteItems
Deletes named user items.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | Pass a JSON object with "items", and "_userItemId" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise<String> - ok: 204 response
let args = {
"items": [<YOUR-ITEM-ARRAY>],
"_userItemId": "5dcbbd24f16c872134947df2"
};
await IafScriptEngine.deleteItems(args);
deleteOrchestratorSchedule
Deletes an orchestrator schedule.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with an "id" property. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
String - ok: 204 response
let req = {
"id": "1eedf5bc-d1f7-4432-9063-c76f84967eb0"
};
await IafScriptEngine.deleteOrchestratorSchedule(req);
deleteRelations
Deletes the record of a relationship between two related items in different collections.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSONObject | Pass a JSON object with "parentUserItemId", and "_userItemId" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise<String> - ok: 204 responselet args = { "parentUserItemId": "5dcbbd24f16c872134947df2", "_userItemId": "5kisnt24f16c907854371pf0" };await IafScriptEngine.deleteRelations(args);
downloadFile
Gets a download URL for a particular file version.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with "fileId" and "versionId" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
String - file URL
let req = {
"_fileId": "9df6e162-acea-11ed-afa1-0242ac120002",
"_fileVersionId": "1wxft3696g2e1a6daa57fh33"
};
let downloadUrl = await IafScriptEngine.downloadFile(req);
dynamicImport
Dynamically imports a script by its criteria, such as its _userType property. Note: If more than one script returns based on the criteria, only the first script loads.
| Parameter | Required | Type | Description |
|---|---|---|---|
| criteria | Yes | NamedUserItemCriteria | Enter a NamedUserItemCriteria object containing a valid simple query. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise<> - A promise to a module namespace object that contains all exports from moduleName.
let criteria = {
"_usertype":"project_setup",
"_name":"projectSetup",
"query": {
"_usertype":"project_setup",
"_name":"projectSetup"
}
};
let myScript = await IafScriptEngine.dynamicImport(criteria);
findInCollections
Looks up named user collections and their related items based on your criteria. Note: This method looks up the tip versions only. To look up multiple versions, use IafItemsvc.searchRelatedItems.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | Pass a findInCollections query without the operator. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
JSON - The query response in JSON. If you add the property and set it to , the data for all the pages appears in the response's property.
findWithRelated
Looks up related items in multiple named user collections with a query you pass.Note: This method looks up the tip versions only. To look up multiple versions, use IafItemsvc.searchRelatedItems.
| Parameter | Required | Type | Description |
|---|---|---|---|
| findArg | Yes | JSON | Pass a $findWithRelated query without the operator. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
JSON - The query response in JSON. If you add the property and set it to , the data for all the pages appears in the response's property.
findWithRelatedGraph
Looks up related items across multiple named user collections, hopping from related item to related item by relationship. You can traverse more than one level of relationship in either a parent-child or child-parent direction to get the data you want.This method looks up the tip versions only. To look up multiple versions, use IafItemsvc.searchRelatedItems.
| Parameter | Required | Type | Description |
|---|---|---|---|
| findArg | Yes | JSON | Pass a findWithRelatedGraph query without the operator. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
JSON - The query response in JSON. If you add the property and set it to , the data for all the pages appears in the response's property.
findWithRelatedMulti
Looks up related items in multiple named user collections with an array of queries you pass. Note: This method looks up the tip versions only. To look up multiple versions, use IafItemsvc.searchRelatedItems.
| Parameter | Required | Type | Description |
|---|---|---|---|
| findArray | Yes | JSON | Pass an array of findWithRelated queries without the operator. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
JSONArray - The query response in JSON. If you add the property and set it to , the data for all the pages appears in the response's property.
getCollection
Gets the first user collection that matches your query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| query | Yes | JSON | Pass an object that contains a "query" parameter with your query object as its value. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| options | No | NamedUserItemCriteriaOptions | Pass a NamedUserItemCriteriaOptions object with your response options, such as "page", "projection", or "sort". |
NamedUserItem - The first user collection that matches your query.
let query = {
query: {"_id": "1e7433c4-a3de-4c15-b8fb-657c1d9b814c"}
};
let options = {
"project": {
"source_id": 1
},
};
let collection = await IafScriptEngine.getCollection(query, options);
getCollectionInComposite
Gets the collections in a composite collection that match your simple query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | Pass the composite collection id. |
| query | Yes | JSON | Pass a valid simple query to target the collections you want. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| options | No | UserCollectionOptions | Pass an UserCollectionOptions object with the options you want, such as userItemVersionId. To return the latest version, add the "getLatestVersion" property and set it to "true". |
Page<NamedUserCollection> - A Page object with the NamedUserCollection objects that match you query
let id = "9_gb_comp_Ip9zmx6o7O";
let query = {
query: {"_userItemId": "8_ta_col_Ik9zmx6o7O"}
};
let options = {
"getLatestVersion": "true",
"userItemVersionId": {
"source_id": 1
}
};
let id = "6333e105026300398e2d653e";
let collection = await IafScriptEngine.getCollectionInComposite(id, query, options);
getCollections
Gets a list of user collections that match a simple query you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| query | Yes | JSON | Pass a JSON object with a "query" parameter. In the "query" property's value, insert a valid MongoDB query to target the named user collections you want. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| options | No | NamedUserItemCriteriaOptions | Pass a NamedUserItemCriteriaOptions object with your options, such as page, projection, or sort. |
Page<NamedUserItem> - A Page object with the NamedUserItem objects that match.let query = { query: {"_userItemId": "3_ba_elem_Ik9zmx6o7O"} };let options = { "project": { "source_id": 1 }, "sort": { "_name": 1 } };let collections = await IafScriptEngine.getCollections(query, options);
getCollectionsInComposite
Gets all the related collections in a named composite item that match your query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | Pass the composite collection id, such as the database id or the _userItemId. |
| query | Yes | JSONObject | Pass a simple query that uses RelatedCollection properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| options | No | UserCollectionOptions | Pass an UserCollectionOptions object with the options you want, such as userItemVersionId. |
| Note: To return the latest version, add the "getLatestVersion" property and set it to "true". |
Page<RelatedCollection> - A page object with the related collections that match your querylet id = "9_gb_comp_Ip9zmx6o7O";let query = { query: {"_userItemId": "5_hz_elem_Ik9zmx6o7O"} };let options = { "getLatestVersion": "true", "userItemVersionId": { "source_id": 1 } };let collections = await IafScriptEngine.getCollectionsInComposite(id, query, options);
getCompositeCollection
Gets a composite collection that matches a simple query you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| query | Yes | JSON | Pass a JSON object with a "query" parameter. In the "query" property's value, insert a valid simple query to target the composite collection you want. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| options | No | NamedUserItemCriteriaOptions | Pass a NamedUserItemCriteriaOptions object with the options you want, such as page, projection, and sort. To return the latest version, add the options.getLatestVersion property and set it to "true". |
NamedUserItem - A NamedUserItem object
let query = {
query: {"_id": "2f6423c4-b3df-4c15-b8fb-657c1d9b642m"}
};
let options = {
"project": {
"source_id": 1
},
"getLatestVersion": true
};
let compositeColl = await IafScriptEngine.getCompositeCollection(query, options);
getCompositeCollections
Gets composite collections that match a simple query you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| query | Yes | JSON | Pass a JSON object with a "query" property. In the "query" property's value, insert a valid simple query to target the composite collections you want. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| options | No | NamedUserItemCriteriaOptions | Pass a NamedUserItemCriteriaOptions object with the options you want, such as page, projection, and sort. |
Page<NamedUserItem> - A page of NamedUserItem objects.
let query = {
query: {"_userItemId": "3_ba_elem_Ik9zmx6o7O"}
};
let options = {
"project": {
"source_id": 1
},
"sort": {
"_name": 1
}
};
let compositeColls = await IafScriptEngine.getCompositeCollections(query, options);
getDatasourceRunStatus
Get an orchestrator's orchRunStatus when you pass an OrchRun id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with a "runid" property. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
getDatasources
Gets orchestrators when you pass namespaces and userType query criteria.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with "_namespaces" and "_userType" properties and values. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<Orchestrator> - A Page object with orchestrator objects that match your query.
let req = {
"_namespaces": ["test_bXgr468E"],
"_userType": "test_instant"
};
let orchestrators = await IafScriptEngine.getDatasources(req);
getDistinct
Gets the distinct field values for related items in a named user collection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | Pass an object with a "field" property. You can also add an "options" property. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<JSON> - A Page of distinct items that match your query
args = {
"getAllUserItems":true,
"collectionDesc": {
"_userItemId": "11_new_ba_elem_1sjwcciumd",
"_versions.all": true
},
"collectionProject": {
"_id": 1,
"_userItemId": 1
},
"field": "type_id",
"query": {}
};
let distinct = await IafScriptEngine.getDistinct(args);
getDistinctMulti
Gets an array of distinct items that match your array of queries.
| Parameter | Required | Type | Description |
|---|---|---|---|
| argArr | Yes | JSON | Pass an array of objects with the following properties: (args: the query to look for items. args.field: the field name for which to return distinct items) |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<JSONObject> - distinct items based on the field name
let argArr = [
{
"collectionDesc": {
"_userItemId": "11_new_ba_elem_1sjwcciumd",
"_versions.all": true
},
"collectionProject": {
"_id": 1,
"_userItemId": 1
},
"field": "type_id",
"query": {}
},
{
"collectionDesc": {
"_userItemId": "13_new_ba_elem_1sjwcciumd",
"_versions.all": true
},
"collectionProject": {
"_id": 1,
"_userItemId": 1
},
"field": "type_id",
"query": {}
},
];
let distinctItems = await getDistinctMulti(argArr);
getDistinctWithCount
Gets an array of distinct items with count.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | the query to look for items. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<JSON> - The array of distinct items.
let args = {
"getAllUserItems":true,
"collectionDesc": {
"_userItemId": "asset_coll_1dB8xLuu8o"
},
"collectionProject": {
"_id": 1,
"_userItemId": 1
},
"fieldDesc": [
{
"field": "properties.dtCategory.val",
"count": "true"
},
{
"field": "properties.dtType.val",
"query": {},
"count": "true"
}
]
}
let res = IafScriptEngine.getDistinctWithCount(args, ctx);
//Sample response
{
"properties.dtType.val": [
{
"count": 2,
"value": "Plaster Board"
},
{
"count": 1,
"value": "Tea and Canteen Tiling"
}
],
"properties.dtCategory.val": [
{
"count": 1,
"value": "Wall & Ceiling Finish"
},
{
"count": 2,
"value": "Ceiling"
}
]
}
getFile
Gets a particular file version's source file.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with "fileId" and "versionId" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise<Buffer> - Returns a Promise object with a buffer of the file stream.
let req = {
"fileId": "5dafe5736f2d3a4dcc55fa14",
"versionId": "1wxft3696g2e1a6daa57fh33"
};
let fileVersion = await IafScriptEngine.getFile(req);
getFileCollection
Gets the first file collection that matches your simple query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| query | Yes | JSON | Pass a JSON object with a "query" property. In the "query" property's value, insert a valid simple query to target the file collection you want. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| options | No | NamedUserItemCriteriaOptions | Pass a NamedUserItemCriteriaOptions object with the options you want, such as page, projection, and sort. |
NamedUserItem - The first file collection that matches your query.let query = { query: {"_id": "9d6423c4-b3df-4c15-b8fb-657c1d9b642m"} };let options = { "project":{"_userType": 1, "_itemClass": 1}, "sort": {"_name": 1}, // -1 for descending order "page": {"_offset": 10, "_pageSize": 20} };let fileColl = await getFileCollection(query, options);
getFileCollections
Gets file collections that match your query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| query | Yes | NamedUserItemCriteria | Pass a NamedUserItemCriteria object to match the file collections you want. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| options | No | NamedUserItemCriteriaOptions | Pass a NamedUserItemCriteriaOptions object with the options you want, such as page, projection, and sort. |
| Note: To return the latest version, add the options.getLatestVersion property and set it to "true". |
Page<NamedUserItem> - A Page object with the NamedUserItem objects that match you query
let query = {
query: {"_userItemId": "3_ba_elem_Ik9zmx6o7O"}
};
let options = {
"project": {
"source_id": 1
},
"sort": {
"_name": 1
}
};
let fileColls = await IafScriptEngine.getFileCollections(query, options);
getFileInfo
Gets File object data when you pass a simple query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with "query" and "options" parameters. In the "query" property's value, insert a valid MongoDB query to target the file you want and its properties. In the "options" property, pass an Options object with your offset and page size preferences. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<File> - A Page object with the File objects that match your query.
let req = {
"query": {
"_tags": "Warranty"
},
"options": {
"_pageSize": 100,
"_offset": 10
}
};
let fileInfo = await IafScriptEngine.getFiles(req);
getFileItems
Gets file items in a named file collection that match your query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | Array<JSON> | Pass an array of JSON objects with basic property-value pairs for the NamedUserCollection type. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<FileItem> - A page object with the file items that match your query
let req = {
"_userItemId": "94_file_col_4GonYYWpov"
};
let fileItems = await IafScriptEngine.getFileItems(req);
getFileItemsMulti
Gets file items in multiple named file collection that match your array of queries. Please keep options.getAllItems true to fetch all the items
| Parameter | Required | Type | Description |
|---|---|---|---|
| getArray | Yes | Array<(JSON | CollectionQuery)> | Pass an array of JSON objects with basic property-value pairs of type NamedFileCollection. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<FileItem> - A page object with the file items that match your query
let req = [
{"_userItemId": "11_file_col_4LeaYYWpsz"},
{"_userItemId": "1mb_file_col2_OYK5UKTTTl"},
{"_userItemId": "22_file_col3_5PTaGGWmlh"}
];
It also accepts collectionDesc
let req = [
{
"collectionDesc": {
"_userItemId": "1801ks-inv-_files_UKFFYde0He"
},
"query": {
"doc_type": "warranty_docs"
},
"options": {
"page": {
"getAllItems": true
}
}
}
];
let fileItems = await IafScriptEngine.getFileItemsMulti(req);
getFiles
Gets a container's file items by the container's path.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with "query" and "options" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
(Array<FileItem> | Page<FileItem>) - Returns an array of FileItem objects. If you set options.pagedRes to true, the method returns a Page object with FileItem objects.
let req = {
"query": {
"_tags": "Warranty"
}
"options": {
"project": {
"source_id": 1
}
},
};
let fileItems = await IafScriptEngine.getFiles(req);
getFileVersionsInfo
Gets file versions when you pass the file's UUID.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with a "fileId" property. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
let req = {
"fileId": "5dafe5736f2d3a4dcc55fa14";
};
let fileVersions = await IafScriptEngine.getFileVersionsInfo(req);
getFileVersionUrl
Gets a download URL for a particular file version. The URL expires after 48 hours.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with "_fileId" and "_fileVersionId" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise<FileVersion> - Returns a promise with the FileVersion object, which includes the download URL.
let req = {
"_fileId": "6336c490017d84b0a506e453",
"_fileVersionId": "6336c490017d84b0a506e45a"
};
let downloadUrl = await IafScriptEngine.getFileVersionUrl(req);
getInverseRelations
Gets the inverse relationships in a named user collection that matches your query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | CollectionQuery | Pass a JSON object with basic property-value pairs of type NamedUserCollection. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<Relationship> - A Page object with the relationships that match your query
let req = {
"_userItemId": "11_new_geom_view_4LeaYYWpsz"
}
let inverseRelations = await IafScriptEngine.getInverseRelations(req);
getItems
Gets items in a named user collection that match your simple query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | CollectionQuery | Pass a JSON object with basic property-value pairs of typye NamedUserCollection. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<RelatedItem> - A page object with the named user items that match your query
let req = {
"_userItemId": "11_new_geom_view_4LeaYYWpsz",
"project": {"source_id": 1}
};
let items = await IafScriptEngine.getItems(req);
getItemsMulti
Gets items in multiple named user collections. This method takes an array of objects to query. You can also use this method to map relations between collections.
| Parameter | Required | Type | Description |
|---|---|---|---|
| getArray | Yes | Array<(CollectionQuery | JSON)> | Pass an array of JSON objects with basic property-value pairs of type NamedUserCollection. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<RelatedItem> - A page object with the named user items that match your query
let req = [
{"_userItemId": "11_sensor_col_4LeaYYWpsz"},
{"_userItemId": "1mb_tel_items_col2_OYK5UKTTTl"},
{"_userItemId": "22_sensors_col3_5PTaGGWmlh"}
];
It also accepts collectionDesc
let req = [
{
"collectionDesc": {
"_userItemId": "1801ks-inv-_ba_ele_UKFFYde0He"
},
"query": {
"dtCategory": "sys_equipments"
},
"options": {
"page": {
"getAllItems": true
}
}
}
];
let items = await IafScriptEngine.getItemsMulti(req);
getItemsOfRelations
Gets the child related items of the relationships you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | Array<JSON> | Pass an array of JSON objects with "_relatedToIds" and "_relatedUserItemId" properties. You can also add optional "options", "options.project", "options.sort", "options.page" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<NamedUserItem> - A Page object with an array of items that match your query
getItemsOfRelationsMulti
Gets the related items of the relationships you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| getArray | Yes | Array<Array<JSON>> | Pass an array of arrays of JSON objects, each with "_relatedToIds" and "_relatedUserItemId" properties. You can also add optional "options", "options.project", "options.sort", "options.page" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<NamedUserItem> - A page object with an array of items that match your query
let req = {
"_relatedToIds": [“002f617e-4d16-43b1-a7fa-981cc30e6dcc”, “982f614f-4g79-63b7-a6fb-981gg30e6dtt”],
"_relatedUserItemId": "samplehouse_geom_file_n8scKhhra7"
};
let childRelatedItems = await IafScriptEngine.getItemsOfRelations(req);
getOrchestratorRuns
Gets all orchestrator runs or those that match a simple query you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | No | JSONObject | Pass an object, or an empty object; only used for namespace/context information. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| criteria | No | JSON | To filter orchestrator runs, pass an object with your simple query, e.g. "_pageSize", "_offset", "_status", "startDate", "endDate" properties. |
let criteria = { _pageSize: 10, _offset: 0, _status: COMPLETED, startDate: 1675839681115, endDate: 1675839758115 };
let orchRuns = await IafScriptEngine.getOrchestratorRuns({}, ctx, criteria)
getOrchestratorSchedule
Gets orchestrator schedules when you pass an orchestrator schedule id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with an "id" property. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
let req = {
"id": "1eedf5bc-d1f7-4432-9063-c76f84967eb0"
};
let schedules = await IafScriptEngine.getOrchestratorSchedule(req);
getOrchestratorSchedules
Gets all orchestrator schedules or those that match a simple query you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | No | JSON | To filter your query, pass a JSON object with OrchSchedule properties and values. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
getRelations
Gets the relationships in a named user collection that match your query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | CollectionQuery | Pass a JSON object with basic property-value pairs of type NamedUserCollection. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<Relationship> - A Page object with the relationships that match your query
let req = {
"_userItemId": "11_new_geom_view_4LeaYYWpsz"
};
let relations = await IafScriptEngine.getRelations(req);
getRelationsMulti
Gets relationships in multiple named user collections when you pass an array of query objects.
| Parameter | Required | Type | Description |
|---|---|---|---|
| getArray | Yes | Array<JSON> | Pass an array of JSON objects with basic property-value pairs of type NamedUserCollection. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<Relationship> - A Page object with the relationships that match your query
let req = [
{"_userItemId": "11_new_geom_view_4LeaYYWpsz"},
{"_userItemId": "1mb_4222225_ba_elem_OYK5UKTTTl"},
{"_userItemId": "22_geom_view2_5PTaGGWmlh"}
];
let relationships = await IafScriptEngine.getRelationsMulti(getArray);
getTelItemsMulti
Gets telemetry items in multiple named telemetry collection that match your array of queries. Please keep options.getAllItems true to fetch all the items
| Parameter | Required | Type | Description |
|---|---|---|---|
| getArray | Yes | Array<(CollectionQuery | JSON)> | Pass an array of CollectionQuery, The _userItemId criteria should be of type NamedTelemtryCollections. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<FileItem> - A page object with the file items that match your query
let req = [
{"_userItemId": "11_sensor_col_4LeaYYWpsz"},
{"_userItemId": "1mb_tel_items_col2_OYK5UKTTTl"},
{"_userItemId": "22_sensors_col3_5PTaGGWmlh"}
];
It also accepts collectionDesc
let req = [
{
"collectionDesc": {
"_userItemId": "1801ks-inv-_sensors_UKFFYde0He"
},
"query": {
"sensor_type": "air_quality",
"floor": 3
},
"options": {
"page": {
"getAllItems": true
}
}
}
];
let fileItems = await IafScriptEngine.getTelItemsMulti(req);
mapItemsAsRelated
Maps an array of parent items to their related items by targeting specific fields.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | Pass a JSON object with "parentItems", "relatedItems", "fromField", and "relatedField" fields. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
mapItemsAsRelatedMulti
Maps multiple related items at a time when you pass parent and child item arrays.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | Pass an array of JSON objects with "parentItems", "relatedItems", "fromField", and "relatedField" fields. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
mapItemsAsRelatedWithCustomAttributes
Maps related items by the _customAttributes value in a Relationship object.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | Pass a JSON object with "parentItems", "relatedItems", "fromContainerField", "customAttributeFields", and "relatedField" fields. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
removeDatasource
Deletes an orchestrator when you pass its id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with an "orchId" property. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
String - ok: 204 response
let req = {
"orchId": "0567d327-87ed-431c-923d-3a4d86ae9105"
};
await IafScriptEngine.removeDatasource(req);
removeRelations
Removes a relationship between two related items in different collections.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | Pass a JSON object with "parentUserItemId", and "_userItemId" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise<String> - ok: 204 response
let args = {
"parentUserItemId": "5dcbbd24f16c872134947df2",
"_userItemId": "5kisnt24f16c907854371pf0"
};
await IafScriptEngine.removeRelations(args);
runDatasource
Posts an orchestrator run by Orch id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with a "orchestratorId" property. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Boolean -
let req = {
"orchestratorId": "0567d327-87ed-431c-923d-3a4d86ae9105"
};
await IafScriptEngine.runDatasource(req);
updateItemsBulk
Bulk updates named user items.
| Parameter | Required | Type | Description |
|---|---|---|---|
| args | Yes | JSON | Pass a JSON object with "items", and "_userItemId" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise<String> - ok: 204 response
updateNamedUserItemVersion
Updates a named user item version when you pass a NamedUserItem object.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with "userItemId", "userItemVersionId", and "version" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
NamedUserItemVersion - The updated named user item version with "_version" and "_isTop" properties.
let req = {
"userItemId": "5dcbbd24f16c872134947df2",
"userItemVersionId": "7gykes28f16c872134947dfb",
"version":
};
let itemVersion = await IafScriptEngine.updateNamedUserItemVersion(req);
updateOrchestrator
Updates an orchestrator.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with an "id" property and the Orchestrator properties and values you want to update. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Orchestrator - The updated Orchestrator object
updateOrchestratorRun
Updates an orchestrator run.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with a "id" property. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
let req = {
"id": "0567d327-87ed-431c-923d-3a4d86ae9105"
};
let updatedOrchRun = await IafScriptEngine.updateOrchestratorRun(req);
updateOrchestratorSchedule
Updates an orchestrator schedule.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with "id" and "runinterval" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
let req = {
"id": "1eedf5bc-d1f7-4432-9063-c76f84967eb0"
"runinterval": "* * 30"
};
let orchSchedule = await updateOrchestratorSchedule(req);
uploadFile
Uploads a file to the file service when you pass a File object. Add callback functions for progress and success events.
| Parameter | Required | Type | Description |
|---|---|---|---|
| file | Yes | File | Pass a File object with the metadata you want, such as namespaces, parents, a filename, and tags. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| onProgress | Yes | Function | Pass your callback function for an onProgress event. |
| onSuccess | Yes | Function | Pass your callback function for an onSuccess event. |
| headers | Yes | FileHeaders | Pass headers, such as "Content-Encoding", to apply to the HTTP request that initiates the file upload. |
File - The created File object from file service with its metadata
let file = { "fileObj": <File or ReadStream>, "name": "warrantyfile.pdf", "_tags": ["test"], "_parents": [] };
await IafScriptEngine.uploadFile(file, ctx);
// Upload file with content type
let fileObj = fs.createReadStream(filePath);
let file = { "fileObj": fileObj, "name": "warrantyfile.pdf"}
let onSuccess = (fileSvcObj) => console.log('upload success');
let headers = {"Content-Type":"application/pdf"}
IafScriptEngine.uploadFile(file, ctx, onSuccess, headers);
uploadJson
Uploads a JSON file to the file service.
| Parameter | Required | Type | Description |
|---|---|---|---|
| req | Yes | JSON | Pass a JSON object with "data" and "filename" properties. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise -
let req = {
"data": {
//<your json data>
}
"filename": "<your filename>""
};
await IafScriptEngine.uploadJson(req);