05-31-2016 04:29 AM
Hi,
Not able to set property of type Datetime in Nuxeo using Automation Scripting (JavaScript). Below is the code snippet:
function run(input, params) {
var d2 = new Date();
d2.setFullYear(d2.getFullYear()+7);
Document.SetProperty(input,{
/*required:true - type: string*/
'xpath':"doc:start_date",
/*required:false - type: boolean*/
'save':true,
/*required:false - type: serializable*/
'value':d2
});
} Below error is occured in Nuxeo, Please suggest how to do property convert:
Caused by: org.nuxeo.ecm.core.api.model.PropertyConversionException: Property Conversion failed from class org.nuxeo.ecm.automation.core.util.DataModelProperties to class java.util.Calendar at org.nuxeo.ecm.core.api.model.impl.primitives.DateProperty.normalize(DateProperty.java:66) at org.nuxeo.ecm.core.api.model.impl.AbstractProperty.setValue(AbstractProperty.java:311) at org.nuxeo.ecm.automation.core.operations.document.SetDocumentProperty.run(SetDocumentProperty.java:68) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
05-31-2016 01:19 PM
Hi Surya,
I believe your JS Date object is not recognized as an instance of Java Calendar.
The exception is being thrown here:
@Override
public Serializable normalize(Object value) throws PropertyConversionException {
if (isNormalized(value)) {
return (Serializable) value;
}
if (value.getClass() == Date.class) {
Calendar cal = Calendar.getInstance();
cal.setTime((Date) value);
return cal;
}
if (value instanceof String) {
String string = (String) value;
if (string.length() == 0) {
return null;
}
return (Calendar) field.getType().decode(value.toString());
}
throw new PropertyConversionException(value.getClass(), Calendar.class);
}
@Override
public boolean isNormalized(Object value) {
return value == null || value instanceof Calendar;
}
Hope this helps.
-Yousuf
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.