on 2022 Jul 13 4:27 AM
Hi All,
I have an Odata response in JSON format where the invoice date is passed as a timestamp. The standard JSON to XML convert function works well except the date.
<CGROSS_AMOUNT_CU>USD</CGROSS_AMOUNT_CU><br><CINVOICE_DATE>/Date(1645660800000)/</CINVOICE_DATE><br><CINVOICE_UUID>028</CINVOICE_UUID>
I have a requirement to covert /Date(1645660800000)/ to yyyy-MM-dd for an XML mapping. The date trans function within the message mapping didn't covert correctly. What is the easiest method? Thanks.
Hello Gabrielu.
Check below groovy script to convert EPOCH time stamp, it will directly give you date. You can manipulate time zone as per your requirment.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.*;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
def Message processData(Message message) {
map = message.getProperties();
Instant i=Instant.ofEpochMilli(1645660800000)
ZonedDateTime z=i.atZone(ZoneId.of("Asia/Calcutta"))
LocalDate date=z.toLocalDate()
message.setProperty("CINVOICE_DATE", date);
return message;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Gabrielu,
i had a similar problem a couple of days ago. The other answers mentioned groovy script. I solved it by using Javascript:
timestamp = timestamp * 1000;
var convertedTimestamp = new Date(timestamp);
"timestamp" here is the unix epoch. I then saved the converted timestamp as a property and used it in my mapping. You could definitely achieve this in groovy script as well if that is a requirement for you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello gabrielu,
Please refer below and you can write groovy script to perform the conversion.
#Leverage JSONSlurper to parse the input JSON ( for particular field )
#2 Write script with below logic.
Regards,
Sriprasad Shivaram Bhat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gabrielu,
For epoch to date conversion, you can use groovy script.
Regards,
Priyanka
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
9 | |
8 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.