Skip to Content

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

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Aug 03, 2017 at 05:52 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 10, 2017 at 08:11 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 03, 2017 at 12:03 PM

    Thank you, Senthil,

    It looks like just what I wanted.

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

    Best regards,

    Aleksei

    .

    Add comment
    10|10000 characters needed characters exceeded