cancel
Showing results for 
Search instead for 
Did you mean: 

Code for setting KM Folder properties(standard & custom)

Former Member
0 Kudos
70

Hi,

How do I programatically set the KM Folder properties(standard as well as custom defined) ?

Also, how do I programatically set KM Document properties(standard & custom) and its Permissions ?

(I have NWDS setup to do the development)

Any API references or code samples or documentation would be of great help

thanks

Ashish

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

You could do something like this...

path is the location of the resource in KM.

namespace is the namespace of the property you would like to set.

name is the id of the property you would like to set.

value is what you want to set it to.


public static boolean setPropertyValueOfResource(String path, String namespace, String name, String value)
{
        try
	{
		RID file = RID.getRID(path);
		IUser user = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");
		IResourceContext rContext = new ResourceContext(user);
		IResource fileResource = ResourceFactory.getInstance().getResource(file, rContext);
		IPropertyName pName = new PropertyName(namespace, name);
		IProperty prop = new Property(pName, value);
		fileResource.setProperty(prop);
		return true;
	}
	catch(NullPointerException E)
	{
		...
	} 
	catch(UserManagementException e)
	{
		...
	} 
	catch(ResourceException e)
	{
		...
	}
}

You can also get the property value of a resource.


public static String getPropertyValueOfResource(String path, String namespace, String name)
{
	try
	{
		RID file = RID.getRID(path);
		IUser user = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");
		IResourceContext rContext = new ResourceContext(user);
		IResource fileResource = ResourceFactory.getInstance().getResource(file, rContext);
		IPropertyName pName = new PropertyName(namespace, name);
		IProperty property = fileResource.getProperty(pName);
				
		return property.getValueAsString();
	}
	catch(NullPointerException E)
	{
		...
	} 
	catch(UserManagementException e)
	{
		...
	} 
	catch(ResourceException e)
	{
		...
	}
}

You can also get the available values for the property


public static String[] getAllowedPropertyValues(String propertyId, String namespace)
{
	try
	{
		IPropertyConfigurationService propConfigService =(IPropertyConfigurationService)ResourceFactory.getInstance().getServiceFactory().getService("PropertyConfigurationService");
 
		IMetaModel metaModel = propConfigService.getMetaModel();
		IPropertyName propertyName = new PropertyName(namespace, propertyId);
		IMetaName metaName = metaModel.searchByPropertyName(propertyName);
		IMetaValueListIterator iterator = metaName.allowedValueIterator();

		String values = "";
				
		while(iterator.hasNext()) 
		{
			IMetaValue m = iterator.next();
			values += m.getValue() + ";";
		}
				
		return values.split(";");
	}
	catch (ResourceException e) 
	{
		...
	}
	catch (PropertyConfigurationServiceException e)
	{
		...
	}
}

Former Member
0 Kudos

Hi Eric,

I used the code suggested by you, but i m getting NullPointerException in the following statement:

IUser user = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");

Please help me out.

Former Member
0 Kudos

Hi

you can use com.sap.netweaver.bc.rf.common.property.SystemPropertyFactory.create....(.....) methods or constructors of some of property classes.

for. e.g.

com.sap.netweaver.bc.rf.common.property.stringtype.StringSingleValueProperty...

daniel_davinci
Active Contributor
0 Kudos

Hi Ashish,

SDN to the rescue.

<a href="https://media.sdn.sap.com/html/submitted_docs/nw_kmc/examples/index.html">KMC Code Samples</a>

<a href="https://sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/kmc/Knowledge%20Management%20and%20Collaboration%20Developers%20Guide.html">KMC Developers Guide</a>

Good Luck

Cheers

Dan