Update ECM Metadata

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business rules examples >

Update ECM Metadata

Overview

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.

 

To update the metadata, use the following function:

 

CHelper.UpdateECMMetadata(Me, data, xPath)

 

The following attributes are needed:

Me: this parameter is fixed.

data: metadata structure.

xPath: corresponds to the data model's file attribute.

 

Example

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

 

Upload File

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

}

 

Files on a table

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

 }

}