Copy the file content from one attribute to another

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business rules examples > File management with expressions >

Copy the file content from one attribute to another

File Attribute

It is possible to copy the contents of a File-type attribute from one attribute to another. Remember that a File-type attribute can hold several files.

 

In the following example, the attached files in the Documents file attribute will be copied to the DocumentsBackup file attribute in order to create a security copy of the documents attached during the Process. These attributes are associated to the Process Entity (called Business Opportunity).

 

AdvanceFilesManagement5

 

The expression would be as follows:

 

AdvanceFilesManagement4

 

//Get array of files

var OriginalFile = Me.getXPath("BusinessOpportunity.Documents");

//Go through the array

for(var i=0; i < OriginalFile.size(); i++)

 

{

//Obtain original file

      var FileCopy = OriginalFile.get(i);

      var Name = FileCopy.getXPath("FileName");

      var Data = FileCopy.getXPath("Data");

//Copy original file in the destination file

      var NewFile = Me.addRelation("BusinessOpportunity.DocumentsBackup");

      NewFile.setXPath("FileName", Name);

      NewFile.setXPath("Data", Data);

 

}

 

note_pin

Remember that the XPath attribute order is essential for this expression to work. FileName must be set before Data.

 

The expression above obtains the array of files stored in the Documents file-type attribute. Then it navigates through the array and obtains the name and data of the file to be copied. Finally each file name and content is copied to the DocumentsBackup attribute.

 

 

Image Attribute

In case the aforementioned attributes are Images, not files, regard the following example (Being the same as the one before, but the required files are now images):

 

AdvanceFilesManagement_new1

 

The expression would be as follows:

 

AdvanceFilesManagement_new2

|

//Get original file data

 var Name = Me.getXPath("BusinessOpportunity.ContractImage.FileName");

 var Data = Me.getXPath("BusinessOpportunity.ContractImage.Data");

//Copy original file in the destination file

 Me.setXPath("BusinessOpportunity.ContractImageBackup.fileName", Name);

 Me.setXPath("BusinessOpportunity.ContractImageBackup.Data", Data);

 

 

The expression above obtains the image data stored in the ContractImage image-type attribute. Then file name and content is copied to the ContractImageBackup attribute.