on 2017 Aug 02 2:02 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you, Senthil,
It looks like just what I wanted.
I will inform you here after I try to implement it.
Best regards,
Aleksei
.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
116 | |
8 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.