Programmatically Setting RMOs – Part 2

In this follow-up article to Programmatically Modifying Configuration Data - Part 1 I will explain how to create or modify the data store related settings of the list or site RMOs (Records Management Options) using code.

I will start with a basic description of the objects, namespaces and assemblies which we will be dealing with in code at the end.

There is an abstract class named Rmo in the HP.Integration.SharePoint.Configuration namespace and two sub classes named ListRmo and SiteRmo which inherits the abstract Rmo class. All these classes are available in HP.Integration.SharePoint.Common.dll.

If you look at the ListRmo or SiteRmo object, there is a DataStoreSettings property which is in fact a property of the abstract base class Rmo. This property is of the type DataStoreRmo, which is another abstract class in the same namespace, HP.Integration.SharePoint.Configuration and in the same assembly HP.Integraton.SharePoint.Common.dll.

The DataStoreSettings object is designed to keep all the data store related properties of the List or Site RMOs. We cannot use the DataStoreRmo abstract class directly, but you can find a sub-class, which inherits this abstract base class, named TrimDataStoreRmo in HP.HPTRIM.Integration.SharePoint.Configuration namespace in HP.HPTRIM.Integration.SharePoint.Common.dll.

The above class diagram explains the relationships of the main components described above and also the main properties of the TrimDataStoreRmo, which I will be explaining below.

The TrimDataStoreRmo object is designed to keep all the TRIM/HPRM specific configuration settings required for List or Site RMOs. As our main focus here is to modify or create the data store specific settings, which are in fact the public properties of TrimDataStoreRmo object, I think it would be better to provide a brief description about the available public properties of the TrimDataStoreRmo object here, before diving into the code.

There are 9 public properties available in this object, which we can set using custom code:

Property NameTypeDetails
1UseSpecifiedboolUse the record type specified in the property SpecifedRecordType to create the site parent container or content container if this flag is set otherwise use the default record type specified in site collection settings.
2SpecifiedRecordTypeDataStoreObjectIf the UseSpecified flag is set, this property must be set and cannot be null and this record type is used for site parent or content container creation.
3UseDefaultClassificationboolUse the default classification specified in site collection settings for the site parent container or content container if this flag is set, otherwise use the classification specified in SpecifiedContainerClassification property.
4SpecifiedContainerClassificationDataStoreObjectIf the UseDefaultClassification is not set, this classification is used for site parent or content container creation if specified.
5RecordClassificationDataStoreObjectThis classification is used to classify the list item records (LIRs) if the Rmo.DoNoCreateContainer is set. This must be specified in this case.
6UseSpecifiedFolderRecordTypeboolUse the folder record type specified in property SpecifiedFolderRecordType if this is set, otherwise use the default container record type specified in the site collection settings during folder management.
7SpecifiedFolderRecordTypeDataStoreObjectSpecified record type for folder management. This property cannot be left null if the UseSpecifedFolderRecordType is set.
8UseDefaultClassificationForFolderboolUse the default classification specified in the site collection settings for folder management if this flag is set, otherwise use the one specified below under SpecifiedFolderClassificaton property.
9SpecifiedFolderClassificationDataStoreObjectSpecify the classification to use during folder management if the UseDefaultClassification flag is not set.



The screen shot below shows the alignment of the above properties on the RMO settings page.

With the above description about the objects and properties involved in modifying the data store specific list or site RMO settings, let’s get into the code. Let’s say we need to modify the data store settings of specified list RMOs, and set them to use the specified record type and classification for container creation. The first step would be to retrieve the available or default settings set for the selected list, using the RmoManager and if there are DataStoreSettings available, that is if this property is not null, cast that property to a TrimDataStoreRmo object instance or create a new instance of TrimDataStoreRmo if there are no specified DataStoreSettings available, and then set the required variable in TrimDataStoreRmo, as shown in the code snippet below.

using HP.Integration.SharePoint;
using HP.Integration.SharePoint.Configuration;
using HP.HPTRIM.Integration.SharePoint.Configuration;

RmoManager rmoManager = null; //This is a disposable object so use this in the using statement
ListRmo specifiedListRmo = null;
TrimDataStoreRmo dataStoreSettings = null;

//Get the correct values for the following variables, 
Guid listId = new Guid("3B34793A-87E8-44AD-8664-C21387A8184D");//list guid 
Guid siteId = new Guid("AB8472F1-8C41-4B42-8145-020081621476");//site guid
Guid siteCollectionId = new Guid("D073DCF5-D3EC-4F0A-9363-ED9A7CA0B351");//site collection guid
Guid farmId = new Guid("693A7967-A0BA-4823-9251-EB61F03DDD39");//farm guid
string listTemplateId = "100";//list template id as a string

//Create an instance of RmoManager
using(rmoManager = new RmoManager())
{
   //Retrieve the specified list rmos using RmoManager
specifiedListRmo = rmoManager.GetListRmo(listId, siteId, siteCollectionId, farmId, listTemplateId, ConfigurationType.Specified);

//ConfigurationType is an enumeration, available in HP.Integration.SharePoint.Configuration   
//namespace in HP.Integration.SharePoint.dll, use the Specified option here to retrieve the
//specified rmos.

   if(null != specifiedListRmo)
   {
       if(null == specifiedListRmo.DataStoreSettings)
       {
          //DataStoreSettings are not available, you could create a new instance here 
          //and assign back to the ListRmo object	
          dataStoreSettings = new TrimDataStoreRmo();
          specifiedListRmo.DataStoreSettings = dataStoreSettings;
       }
       else
       {
          //Cast the DataStoreSettings to TrimDataStoreRmo
          dataStoreSettings = (TrimDataStoreRmo)specifiedListRmo.DataStoreSettings;           
       }
                        
       	//Get the correct Uris and titles from the record type and classification
       	string recordTypeUri = "1";
       	string recordTypeTitle = "Title of specifed record type";
       	string classificationUri = "1";
       	string classificationTitle = "Title of specifed calssification";

//Set the flag to use the specifed record type instead of the default given in site collection  //settings
       	dataStoreSettings.UseSpecified = true;
                    
       	//Create a new DataStoreObject and assign that as the specified record type
       	//DataStoreObject is the type used to represent any of the data store objects, record 
       	//type, classification etc. in the above case it is a record type.
       	dataStoreSettings.SpecifiedRecordType = new DataStoreObject(recordTypeUri, recordTypeTitle);

//Reset this flag to use the specifed classification instead of the default given in the site //collection settings
       	dataStoreSettings.UseDefaultClassification = false;
//Create a new DataStoreObject to represent the sepecified classification and assign it to //SpecifiedContainerClassification
dataStoreSettings.SpecifiedContainerClassification = new DataStoreObject(classificationUri,  classificationTitle);

        //Save the modified rmos back here using the RmoManager
        rmoManager.SaveListRmo(specifiedListRmo,siteId,siteCollectionId,farmId);
 
    }
    else
    { 
	//This is a very unlikely situation as the RmoManager always returns minimum the
        //default rmo configuration for the given list based on the template or default for any list.
    }
}

You can also modify the SiteRmo object in the same manner to set the DataStoreSettings using the appropriate methods in the RmoManager to retrieve and save the site RMOs.

Many thanks to Wineya Wijesinghe on the team, for this great post!