ebs.massInsertDynamicEbs
Inserts multiple records in an entity based on the output from a fetch. A single attribute of the inserted records can be populated using the fetch output. For the remaining attributes, you can only apply a set of static values.
Syntax
Copy
function ebs.massInsertDynamicEbs(massInsertDynamicRequest: IMassInsertDynamicRequest, callback: Function, errorCallback?: Function): void;
| Parameter | Type | Description |
|---|---|---|
massInsertDynamicRequest
|
IMassInsertDynamicRequest | Details about the insert parameters. |
callback
|
Function | Callback function to run on the returned fields. |
errorCallback? (optional) |
Function | Callback function to run in case of failure. |
Type Aliases
Details about the insert parameters.
Copy
{
"EntityName": string,
"Values": [
{
"Attribute": string,
"Value": any
},
...
],
"Fetch": fetch,
"FetchFieldName": string,
"DestinationFieldName": string
}
| Parameter | Type | Description |
|---|---|---|
| EntityName | string | Name of the entity where the records will be inserted. |
| Values | any[] | Array of JSON objects containing static values to be set for specific attributes of each inserted record. |
| Attribute | string | Name of the attribute to be assigned a static value. |
| Value | any | Value to be assigned to the specified attribute. |
| Fetch | any | Fetch query that returns the attribute values to be dynamically populated in the entity. |
| FetchFieldName | string | Alias of the field in the fetch result set that will be used as input for the dynamically populated attribute. |
| DestinationFieldName | string | Name of the attribute to be populated dynamically using input from the fetch. |
Return Value
Returns details about the insert operation in a JSON object that can be used as input for the callback function.
For example:
Copy
{
"Id": "071de2b6-5e4c-400a-9c38-3a0e4b4cc3f0",
"Message": "Dynamic records inserted: 5",
"IsSuccess": true,
"ClientScript": null,
"ErrorCode": 0,
"Serialized": "{\"Id\":\"071de2b6-5e4c-400a-9c38-3a0e4b4cc3f0\",\"Message\":\"Dynamic records inserted: 5\",\"IsSuccess\":true,\"ClientScript\":null,\"ErrorCode\":0,\"Serialized\":null,\"UIResult\":null,\"AdditionalInfo\":{}}",
"UIResult": null,
"AdditionalInfo": {}
}
Examples
In this example:
- We create a fetch that returns all the values of the customerName attribute from the customers entity and store its code in the myFetch variable.
- We define the displayResult callback function that uses the ebs.showMessage function to display the Details of the insert operation on screen.
- We store the current date and time in the currentDate variable.
- We use the logCustomerNames button to insert all the customer names in the customersLog entity:
- We populate the date attribute with the current date.
- We populate the nameOfTheCustomer attribute with the customer names extracted using the fetch (via the cn alias).
- We use the displayResult function to display the details of the insert operation on screen.
Copy
var myFetch = {"entity":
{
"alias": "base",
"name": "customers",
"attributelist": [
{
"name": "customerName",
"alias": "cn",
"attributeType": 3
}
]
}
}
function displayResult(callbackContent){
ebs.showMessage(callbackContent.Details)
};
var currentDate = new Date()
/* Click event for the logCustomerNames button */
$('#logCustomerNames').on('click', function (event)
{
ebs.massInsertDynamicEbs
(
{
'EntityName' : 'customersLog',
'Values' : [
{'Attribute' : 'date',
'Value' : currentDate}
],
'Fetch' : myFetch,
'FetchFieldName' : 'cn',
'DestinationFieldName' : 'nameOfTheCustomer'
}, displayResult, null
)
});