Cloning Insurance Products
This functionality allows the user to generate a new insurance product based on an existing one. The cloned product captures all the available information from the original product. The user must select an existing product and press the Clone button available on the product view. This action triggers the opening of a specific pop-up form where the user can insert a new name and a new code for the new product. Upon saving, the clone product is generated, in Draft status.
Read below about the endpoints, scripts and libraries used for implementing this functionality.
Endpoints
The following endpoints are used to perform the cloning process:

This endpoint receives an object as a parameter. The object contains the product name and code inserted in the cloning pop-up form, connected to the original product. The endpoint takes those values and validates them, to make sure there is no other product with the same name and code.

This endpoint receives an object as a parameter. The object contains the new product name and code, obtained from the original product form. The script linked to this endpoint takes these values and inserts a cloned product in the system. The clone product contains the same data, similar to the original one.
Server Side Script Libraries
FTOS_IP_InsuranceProduct_Clone
This library is used to clone insurance products. From this library, the following functions are used:

This object wraps smaller functions that fetch data from different entities.

This function fetches the Name and the Code of an insurance product based on a given name or code.
Input parameters:
-
entityName
- The name of the entity on which the fetch will be made. -
ipName
- The name of the new insurance product. -
ipCode
- The code of the new insurance product.
Output parameters: A list of insurance products, found by name or code.

This function fetches the Id of an entity based on a given name from the entity metadata.
Input parameters: entityName
- The name of the entity needed.
Output parameters: The Id of the entity, found by the fetch.

From the FTOS_VersionSettings entity, this function fetches all the records related to the entity that is about to be cloned.
Input parameters: selectedEntity
- The Id of the entity from which the record is about to be cloned.
Output parameters: A list of all the related records.

From the FTOS_VersionSettingsItem entity, this function fetches all the items related to the entity that is about to be cloned.
Parts of the product are stored in different entities, for more details see the Importing Insurance Products page.
Input parameters: versionSettingsid
- The Id of the entity that is about to be cloned.
Output parameters: A list of all the related items.

This function subtracts the first letter from an entity name to use it as an alias.
Input parameters: entityName
- The name of the entity.
Output parameters: The first letter from the entity name.

This function fetches the data from an entity. The fetch uses the entity name received as input and it searches according to the conditions written by two other parameters: the attribute name and the value it should have.
Input parameters:
-
entityName
- The name of the entity on which the fetch is performed. -
conditionAttrName
- The name of the attribute found inside the condition. -
conditionRecord
- The value of the attribute found inside the condition.
Output parameters: A list of all the records returned by the fetch.

This object wraps smaller functions that validate different sets of data.

This function checks if the value received through a parameter is valid. If the value is valid, the function returns true. Otherwise, it returns false.
Input parameters: value
- The value which is about to be validated.
Output parameters: Boolean value (true/ false).

From the client side, this function receives the values inserted into the fields of the cloning pop-up - namely, the values for Name and Insurance Product Code. If the values come in as being empty or invalid, an exception will be thrown to inform the user. The same thing happens if the values are already used by the system (an existing insurance product has the same name or the product code).
Input parameters:
-
entityName
- The name of the entity on which the fetch will be made. -
ipName
- The name of the new insurance product. -
ipCode
- The code of the new insurance product.
Output parameters: If no exception is thrown, the function quits and the cloning process moves on.

This object wraps functions that perform various steps of the cloning process.

This function receives a list of Version Setting Items as a parameter and loops through it for cloning each one of the items into the new product.
Input parameters:
-
versionSettingsItems
- The list of the version setting items. -
productId
- The Id of the product which is about to be cloned. -
newCloneId
- The Id of the new product that receives all the data from the original one.
Output parameters: N/A.

This function inserts into an entity an object with data, both received as a parameter, after some validations are being made on a few attribute names.
Input parameters:
entityName
- The name of the entity on which the insert will be made.
entityData
- The object containing all the data from the original product.
productId
- The id of the cloned product.
Output parameters: Returns an Id of the newly inserted record.

This function is similar with the function above. The function inserts into an entity an object with data, both received as a parameter, after some validations are being made on a few attribute names.
Input parameters:
-
entityName
- The name of the entity on which the insert is made. -
entityData
- The object containing all the data from the original product. -
recordId
- The Id of the product which is about to be cloned. -
relatedAttr
- The name of an attribute that get as value therecordId
parameter.
Output parameters: Returns an id of the newly inserted record

This function the function firstly fetches from the entity metadata a record based on an name received through the parameter. After that, another fetch is made on the FTOS_VersionSettingsItem entity using the Id obtained from the fetch before as a condition for the parentVersionedEntity
attribute.
Input parameters: entityName
- The name of the entity on which the fetch is made.
Output parameters: Returns a list of all the records found by the second fetch.

This function returns the value of a record’s primary key from an entity with a specified name.
Input parameters:
-
entityName
- The name of the entity from which the primary key is needed. -
record
- The record from the entity.
Output parameters: The primary key value.

This function clones all the related entities of a product along with their "children" entities.
Parts of the product are stored in different entities, for more details see the Importing Insurance Products page.
Input parameters:
-
entityName
- The name of the entity on which the fetch is made. -
recordToBeClonedId
- The Id of the record which is about to be cloned. -
recordToBeClonedPrimaryAttribute
- The Id of the record’s primary attribute. -
clonedRecordId
- The Id of the new record.
Output parameters: N/A

This function calls all the other functions (detailed above) for validating, inserting and updating all the data for the product to be cloned.
Input parameters:
-
entityName
- The name of the entity on which the fetches are made. -
productId
- The Id of the product that is about to be cloned. -
ipName
- The name of the new insurance product. -
ipCode
- The code of the new insurance product.
Output parameters: N/A

This function returns all the attributes from an entity.
Input parameters: entityName
- The name of the entity on which the fetches are made.
Output parameters: query
- The resulting array, with all the attributes.