Object for the attachments



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 0

Like

8 comments

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

Angela Reyes,

 

Is it possible to copy the attachments from one object to another by copying the binary data from "data" column of the object.

 

Regards

Sivanesan

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[]).

 

Can you please show how exactly you copy data in your bp?

Dmytro Vovchenko,

PFB

 

 

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();
	    }

 

Dmytro Vovchenko,

 

I was able achieve it using the "Add data" itself. I missed to update/add the attachment type. After I added it I am able to open the attachment. Thanks for your input.

Show all comments