cancel
Showing results for 
Search instead for 
Did you mean: 

How to copy attachments from a BO to another in ABSL?

abelousov
Active Participant
0 Kudos

Hi,

In ByD I have an instance of a BO with some attachments. I would like to copy the instance to another instance. Copying of instance is not difficult to implement in ABSL, but how could I copy the attachments as well?

Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

Hi Aleksi,

Copying Instance in ABSL can be achieved by creating an empty instance and assign the parameters in the source to the newly created one.

Sample Implementation 😉

// Here I'm copying attachment from activity XBO to my custom BO
var activity = ActivityTask.Retrieve(ActivityUUID);
var Attachment;

if (activity.IsSet())
{
	if (activity.AttachmentFolder.IsSet())
	{
		Attachment = activity.AttachmentFolder; // storing/assigning/copying attachment instance in a variable
	}
}

if (Attachment.IsSet())
{
	var attach = this.AttachmentFolder.Create(); // creating attachment instance in my custom BO 
	var doc = Attachment.Document.Where(n => n.IsSet());
	if (doc.Count() > 0)
	{
		var document = doc.GetFirst();
		var binObject;
		var docName;
		var docAltName;
		var docDesc;
		var docType;
		
		if (document.FileContent.IsSet())
		{
			var fileContent = document.FileContent;
			if (!fileContent.BinaryObject.content.IsInitial())
				binObject = fileContent.BinaryObject;
			else
				return;
		}

		if (!document.Name.IsInitial())
			docName = document.Name;
		else
			return;
		if (!document.AlternativeName.IsInitial())
			docAltName = document.AlternativeName;
		else
			return;		
		if (!document.Description.content.IsInitial())
			docDesc = document.Description;
		else
			return;		
		if (!document.TypeCode.content.IsInitial())
			docType = document.TypeCode;
		else
			return;		
		attach.CreateFile(docType, docName, docAltName, docDesc, binObject); // create attachment file with source parameters
	}
}

Regards,

Senthil

Answers (2)

Answers (2)

abelousov
Active Participant

Hi, Senthil,

I have checked, your code definitely works.

For my case I simplified it in such a way:

// Copy attachments
var attachmentfolder = newBO.AttachmentFolder.Create();
foreach ( var document in this.AttachmentFolder.Document ) {
	if ( document.FileContent.IsSet() )	{
		attachmentfolder.CreateFile ( document.TypeCode,
                                              document.Name,
                                              document.AlternativeName,
                                              document.Description,
                                              document.FileContent.BinaryObject );
	}
}

Here, the attachments are being copied from this to newBO.

Thanks a lot for help.

Best regards,

Aleksei

abelousov
Active Participant
0 Kudos

Thank you, Senthil,

It looks like just what I wanted.

I will inform you here after I try to implement it.

Best regards,

Aleksei

.