Avalados por :

Cómo devolver el payload cuando la fecha no es el primer día del mes

  • Creado 01/03/2024
  • Modificado 01/03/2024
  • 2 Vistas
0
Cargando...

Hi Experts,

I have written a groovy to check if the newDate in the payload is firstDayOfMonth or not, to set an XML body. I am facing issues, when the newDate is not the firstDayOfMonth.

I want the same payload if the newDate in the payload is not equal to firstDayOfMonth. I removed the else condition, but the Iflow fails. Please suggest how should I return the payload in else condition.(P.S: I am very new to progamming)

Please suggest as I am running out of time and making some silly mistakes.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import groovy.xml.MarkupBuilder
import java.time.LocalDate
import java.time.format.DateTimeFormatter


def Message processData(Message message) {
    
    Reader reader = message.getBody(Reader)
    map = message.getProperties();
    value = map.get("lastWeekNew");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'00:00:00.000");
    Date newDate = sdf.parse(value);
    def result = newDate - 1;


    Calendar cal = Calendar.getInstance();
    cal.setTime(newDate);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    Date firstDayOfMonth = cal.getTime();
    
   // Define XML parser and builder
    def body = new XmlSlurper().parse(reader)
    def writer = new StringWriter()
    def builder = new
            
            
Pedro Pascal
Se unió el 07/03/2018
Pinterest
Telegram
Linkedin
Whatsapp

1 Respuestas

0
Cargando...

¡El Groovy a continuación funcionó!

import com.sap.gateway.ip.core.customdev.util.Message;
        import java.util.HashMap;
        import java.text.SimpleDateFormat;
        import java.util.Date;
        import java.util.Calendar;
        import java.util.GregorianCalendar;
        import groovy.xml.MarkupBuilder
        import java.time.LocalDate
        import java.time.format.DateTimeFormatter
        def Message processData(Message message) {
            Reader reader = message.getBody(Reader)
            map = message.getProperties();
            value = map.get("lastWeekNew");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'00:00:00.000");
            Date newDate = sdf.parse(value);
            def result = newDate - 1;
            Calendar cal = Calendar.getInstance();
            cal.setTime(newDate);
            cal.set(Calendar.DAY_OF_MONTH, 1);
            Date firstDayOfMonth = cal.getTime();
            // Define XML parser and builder
            def body = new XmlSlurper().parse(reader)
            def writer = new StringWriter()
            def builder = new MarkupBuilder(writer)
            def payload = message.getBody(String);
            // Define target payload mapping
            
            
Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019

contacto@primeinstitute.com

(+51) 1641 9379
(+57) 1489 6964

© 2024 Copyright. Todos los derechos reservados.

Desarrollado por Prime Institute

¡Hola! Soy Diana, asesora académica de Prime Institute, indícame en que curso estas interesado, saludos!
Hola ¿Puedo ayudarte?