Skip to Content
0

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

Aug 02, 2017 at 01:02 PM

166

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Senthil Murugan Aug 03, 2017 at 05:52 AM
3

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

Share
10 |10000 characters needed characters left characters exceeded
Aleksei BELOUSOV Aug 10, 2017 at 08:11 PM
1

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

Share
10 |10000 characters needed characters left characters exceeded
Aleksei BELOUSOV Aug 03, 2017 at 12:03 PM
0

Thank you, Senthil,

It looks like just what I wanted.

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

Best regards,

Aleksei

.

Share
10 |10000 characters needed characters left characters exceeded