Property Conversion failed

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)
1 votes

1 answers

2152 views

ANSWER



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;
}

source: https://github.com/nuxeo/nuxeo/blob/434093e97825bf7e02578efd428e71f588704f20/nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/primitives/DateProperty.java

Hope this helps.

-Yousuf

0 votes