Not Able to Set Date Type in JCR Property in AEM Metadata
Hi All,
I have written the below Groovy script for setting up the one of the Sitecore Date Reviewed value in the AEM metadata as Date type. But the issue is that date is storing as String Type , not as Date Type.
************************ Below is the Groovy Script *******************
import java.text.SimpleDateFormat
import java.util.Date
def metadataNode = session.getNode(newTopicPath + "/jcr:content/metadata")
if (metadataNode == null) {
LOG.debug("Metadata node missing for the asset ${newTopicPath}")
return
}
else {
metadataNode.setProperty("displayTitle", displayTitle)
SimpleDateFormat reviewDateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'")
def dateSiteCore = "20240213T060000Z" // this date I am getting from Sitecore JSON
def nextReviewDate = parseDate(dateSiteCore, reviewDateFormat)
LOG.debug("NONcpmMetadata reviewedDate == ${nextReviewDate}")
metadataNode.setProperty("mc:nextReviewDate", nextReviewDate)
}
session.save()
// Here the method parseDate below
def parseDate(inputTime, dateFormat) {
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
try {
Date inputDate = dateFormat.parse(inputTime)
return outputFormat.format(inputDate)
} catch (ParseException pe) {
/* Empty Catch Statement, for handling multiple date formats.*/
}
return ""
}
After I run the above Script nextReviewDate value is storing as String Type in the metadata but not as Date Type , as shown below screenshot.

Can anyone Please let me Know if I am missing something.
Thanks & Regards
Sonu