Hi there,
Can someone please let me where in the CRM are all the attachments stored in the database?
So say if I attach a file in the Attachment and Notes tab in the Contacts section, I know that the Attachments detail is called Contact's Detail but which object holds those attachments in the database?
Thanks,
AK
Like
Hello,
All files are stored as binary data in the "data" column of the object. Each one is stored in their own column, for example 'ActivityFile'
Best regards,
Angela
Hi,
If the field "Data" contains a correct value and not something like "0x" then yes, you can take this data and add it to another object.
For example, you can do it inside a business process script task.
var fileName = file.GetTypedColumnValue<string>("Name"); var fileType = file.GetTypedColumnValue<Guid>("TypeId"); var fileData = file.GetBytesValue("Data"); var fileEntity = new ActivityFile(userConnection); fileEntity.SetDefColumnValues(); fileEntity.SetColumnValue("ActivityId", activity.Id); fileEntity.SetColumnValue("TypeId", fileType); fileEntity.SetColumnValue("Name", fileName); fileEntity.SetColumnValue("Data", fileData); fileEntity.Save();
Dmytro Vovchenko,
Thanks for the response Dmytro. I am trying to copy the attachments from section A to section B. I have used "Add Data" element inside a BP to copy the data from A to B. The BP runs without any issue but when I try to open the same attachment from section B its throwing below error.
When I queried the object the attachments(both the sections) , it just shows the data type(System.Byte[]).
It looks like you cannot use "Add record" and "Read record" in this case because they cannot work with the "Data" type. You really need to use a script-task to read and add file:
var ESQ = new EntitySchemaQuery(manager, AccountFile); ESQ .AddColumn("Name"); ESQ .AddColumn("Data"); ESQ .AddColumn("Type"); var dataQueryResult = ESQ.GetEntityCollection(userConnection); foreach(Entity file in dataQueryResult) { var fileName = file.GetTypedColumnValue<string>("Name"); var fileType = file.GetTypedColumnValue<Guid>("TypeId"); var fileData = file.GetBytesValue("Data"); var fileEntity = new ContactFile(userConnection); fileEntity.SetDefColumnValues(); fileEntity.SetColumnValue("CintactId", contact.Id); fileEntity.SetColumnValue("TypeId", fileType); fileEntity.SetColumnValue("Name", fileName); fileEntity.SetColumnValue("Data", fileData); fileEntity.Save(); }