cancel
Showing results for 
Search instead for 
Did you mean: 

How to add allowed values to the property from code?

former_member188498
Active Participant
0 Kudos

Hi,

Is it possible to add allowed value for a defined property from code? And how can I do that? Its easy to get allowed values from code, but its not so easy to add allowed values.

The following piece of code does exactly that, but its not working when the allowed value list is empty (allowed values are not being added).

	try
	{
		IPropertyConfigurationService propConfigService =
			(IPropertyConfigurationService) ResourceFactory.getInstance().
getServiceFactory().getService("PropertyConfigurationService");
			
		IMetaModel metaModel = propConfigService.getMetaModel();
		
		String namespace = wdContext.currentPropertiesElement().getPropertyNamespace();
		String name = wdContext.currentPropertiesElement().getPropertyName();
		
		IPropertyName propertyName = new PropertyName(namespace, name);
		
		IMetaName metaName = metaModel.searchByPropertyName(propertyName);

		IMetaValue metaValue = metaModel.createMetaValue(metaModel, metaName, 
			new DefaultMetadataExtension(metaModel), propValue);

		IMetaValueListIterator iterator = metaName.allowedValueIterator();
		while (iterator.hasNext())
		{
			iterator.next();
		}
		
		iterator.add( metaValue );
	}
	catch (ResourceException e)
	{
		MessageManager msgMgr = (MessageManager)wdComponentAPI.getMessageManager();
		msgMgr.reportWarning(e.toString());
	}
	catch (PropertyConfigurationServiceException e)
	{
		MessageManager msgMgr = (MessageManager)wdComponentAPI.getMessageManager();
		msgMgr.reportWarning(e.toString());
	}

Am I doing something wrong? Is there another way to accomplish this? Maybe somebody has had the similar problem like this?

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

Hi Ladislav,

DefaultMetadataExtension implements IDynamicValues. IMetaValueList IDynamicValues.getAllowedValues().

IMetaValueList.add(IMetaValue element).

Best regards, Maksim Rashchynski.

Answers (0)