Set file metadata through a rule

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Document Templates > Advanced topics in document templates > ECM integration > Setting the ECM in Bizagi >

Set file metadata through a rule

Overview

Setting the metadata for a file refers to filling out information fields whenever you integrate your corporate ECM document repository.

This section presents an alternative for filling out metadata, to the one presented at Setting the ECM in Bizagi.

 

Filling out metadata

By default, a document uploaded through the ECM control will allow users to manually edit this information.

However and when using ECM integration, there are scenarios in which you may want to automatically map business information into a document to be stored at the ECM.

 

This means that you may choose to use a business rule which sets information of the case into the repository's folder metadata.

 

The examples below illustrates the methods to use in a rule which automatically maps information into the uploaded document.

 

Example 1

In this example, we map information already contained in our case into the Title and Description metadata.

Our ECM file upload is set in MyProcessEntity.MyFileAttribute.

 

var xPath = "MyProcessEntity.MyFileAttribute"; //this XPath corresponds to the data model's file attribute

var metadataHash = new Hashtable(); //this creates a temporary structure to hold metadata

 
metadataHash.Add("Title", <MyProcessEntity.CustomerNameAttribute>);

metadataHash.Add("Description", <MyProcessEntity.SomeDescriptionAttribute>);

//do this to set each metadata field

 
var tmpFileAttribute = Me.getXPath(xPath); //this obtains all information in the file attribute
for(var i=0; i < tmpFileAttribute.size(); i++) //iteration is done, as this file could contain more than 1 document

{

 var tmpFile = tmpFileAttribute.get(i); //this obtains the actual document

 var idFileUpload = tmpFile.getXPath("id"); //this obtains the id for the actual document

 var completeXpath = xPath + "[id=" + idFileUpload + "]";  //this builds the complete XPath to reference each document

 CHelper.UpdateECMMetadata(Me, metadataHash, completeXpath); //method to map metadata

}

 

Example 2

In this example, our rule is set outside of a table, but we will map metadata for all uploads inside of a table.

This means that we map Title and Description metadata (information already contained in our case), for an ECM file upload which is contained in MyProcessEntity.MyCollection.MyFileAttribute. (as a column of a table).

 

var xPath = "MyFileAttribute"; //this XPath corresponds to the data model's file attribute
var xPathContext = "MyProcessEntity.MyCollection"; //this XPath corresponds to the context of the actual table

var metadataHash = new Hashtable(); //this creates a temporary structure to hold metadata

 

metadataHash.Add("Title", <MyProcessEntity.CustomerNameAttribute>);
metadataHash.Add("Description", <MyProcessEntity.SomeDescriptionAttribute>);

 

var List = Me.getXPath(xPathContext); //this obtains the information in the table
var Array = CHelper.GetValueAsCollection(List);

 
for (var j=0; j < Array.size(); j++) //iteration is done for the records of that table
{
 var tmpRecord = Array.get(j); //this obtains the actual record
 var FileAttrib = tmpRecord.getXPath(xPath); //this obtains all information in the file attribute

 var idRecord = tmpRecord.getXPath("id"); //this obtains the id for the actual record

 
 for(var i=0; i < FileAttrib.size(); i++) //iteration is done, as this file could contain more than 1 document

 {

         var SubFile = FileAttrib.get(i);  //this obtains the actual document of that record

         var idFileUpload = SubFile.getXPath("id");  //this obtains the id for the actual document

         var completeXpath = xPathContext + "[id=" + idRecord + "]." + xPath + "[id=" + idFileUpload + "]"; //this builds the complete XPath to reference each document

         CHelper.UpdateECMMetadata(Me, metadataHash, completeXpath); //method to map metadata

 }

}