Currently, Creatio AI does not support working with files using custom methods out of the box. However, it is possible to achieve this functionality by utilizing development techniques to convert files into a text format and a business process.
Below is an example of a C# script that extracts data from a file stored in a Creatio entity and converts it into a text format:
This script retrieves a file stored in the ActivityFile entity, extracts its binary data, and converts it to a UTF-8 string.
// Define the ID of the file (ActivityFile record)
Guid activityFileId = new Guid("3653b1f0-aa8d-52f6-065b-01642df9c33b");
This specifies the unique identifier (GUID) of the file to be retrieved. In a real scenario, this could be dynamically obtained from a process parameter or another source.
// Get the EntitySchemaManager to interact with Creatio entities
var entitySchemaManager = UserConnection.EntitySchemaManager;
var activityFileSchema = entitySchemaManager.GetInstanceByName("ActivityFile");
var activityFileEntity = activityFileSchema.CreateEntity(UserConnection);
These lines fetch the ActivityFile entity schema, which stores uploaded files related to activities (such as email attachments or documents).
// Retrieve the file record from the database
activityFileEntity.FetchFromDB(activityFileId);
This loads the file record from the Creatio database using the given activityFileId.
// Get the binary data of the file
var blobData = activityFileEntity.GetColumnValue("Data");
// Get the file name
var name = activityFileEntity.GetTypedColumnValue("Name");
*blobData stores the actual file content in binary format (if available).
*name stores the file name as a string.
if (blobData != null)
{
// Convert the binary data to a UTF-8 string
string decodedString = System.Text.Encoding.UTF8.GetString(blobData as byte[]);
// Store the decoded text in a process parameter
Set("DecodedDataParameter", decodedString);
}
else
{
// If no binary data exists, return the file name instead
Set("DecodedDataParameter", name);
}
return true;