cancel
Showing results for 
Search instead for 
Did you mean: 

Default date for custom km property

dhagigeorgiou
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello everyone,

I am trying to create in the KM a custom file property which will be assigned automatically the default date once the file new file is saves.

I have tried various combos all unsuccesful

using Type => Date, Timestamp

Property Renderer => creationdate in the definition of the property metadata.

Is there anyone outher that has done this? I would be very grateful if you could point me to the right direction.

Thanks

Dimitris

Accepted Solutions (0)

Answers (1)

Answers (1)

praveenkumar_gudapati
Active Contributor
0 Kudos

Hello Dimitris,

To create custom Date/TimeStamp property for a Resource, I used this code:

String[] datePatterns = new String[] { "dd.MM.yyyy HH:mm:ss", "dd.MM.yyyy", "yy.MM.dd'/'HH:mm" };

ICollection collection = (ICollection) getOrCreateResource(targetFolderName, resourceContext);
IMutablePropertyMap propMap = new MutablePropertyMap();
if (metaName.getType().equals("Timestamp")) {
    prop = new MutableProperty(propName, org.apache.commons.lang.time.DateUtils.parseDate(propValue, datePatterns));
} else if (metaName.getType().equals("Date")) {
    prop = new MutableProperty(propName, org.apache.commons.lang.time.DateUtils.parseDate(propValue, datePatterns));
}
propMap.put(prop);
IResource actualResource = collection.createResource(targetFileName, props, newContent, false);

Greetings,

Praveen Gudapati

p.s. Points are always welcome for helpful answers