cancel
Showing results for 
Search instead for 
Did you mean: 

Combining Multiple records basing on a field value.

0 Kudos

Hi Experts,

Sample Payload Below.

Is there any standard way to do this?

Please suggest how can i achieve this.

Thanks In advance.

<EmployeeTimeSheet><EmployeeTimeSheet> <approvalStatus>APPROVED</approvalStatus> <lastModifiedDateTime>2022-11-09T09:10:31.000</lastModifiedDateTime> <employeeTimeSheetEntry> <EmployeeTimeSheetEntry> <lastModifiedDateTime>2022-11-08T07:03:04.000</lastModifiedDateTime> <quantityInHoursAndMinutes>1:00</quantityInHoursAndMinutes> <startTime>1970-01-01T09:00:00.000</startTime> <timeTypeName>Mission Days</timeTypeName> <endTime>1970-01-01T10:00:00.000</endTime> <startDate>2022-08-07T00:00:00.000</startDate> </EmployeeTimeSheetEntry> <EmployeeTimeSheetEntry> <lastModifiedDateTime>2022-11-08T07:03:29.000</lastModifiedDateTime> <quantityInHoursAndMinutes>1:00</quantityInHoursAndMinutes> <startTime>1970-01-01T09:00:00.000</startTime> <timeTypeName>Permission</timeTypeName> <endTime>1970-01-01T10:00:00.000</endTime> <startDate>2022-08-08T00:00:00.000</startDate> </EmployeeTimeSheetEntry> </employeeTimeSheetEntry> <userId>2027</userId> </EmployeeTimeSheet> <EmployeeTimeSheet> <approvalStatus>APPROVED</approvalStatus> <lastModifiedDateTime>2022-11-09T09:10:39.000</lastModifiedDateTime> <employeeTimeSheetEntry> <EmployeeTimeSheetEntry> <lastModifiedDateTime>2022-11-08T07:12:25.000</lastModifiedDateTime> <quantityInHoursAndMinutes>1:00</quantityInHoursAndMinutes> <startTime>1970-01-01T09:00:00.000</startTime> <timeTypeName>Mission Days</timeTypeName> <endTime>1970-01-01T10:00:00.000</endTime> <startDate>2022-08-14T00:00:00.000</startDate> </EmployeeTimeSheetEntry> <EmployeeTimeSheetEntry> <lastModifiedDateTime>2022-11-09T07:25:56.000</lastModifiedDateTime> <quantityInHoursAndMinutes>2:00</quantityInHoursAndMinutes> <startTime>1970-01-01T09:00:00.000</startTime> <timeTypeName>Mission Days</timeTypeName> <endTime>1970-01-01T11:00:00.000</endTime> <startDate>2022-08-18T00:00:00.000</startDate> </EmployeeTimeSheetEntry> <EmployeeTimeSheetEntry> <lastModifiedDateTime>2022-11-09T07:25:56.000</lastModifiedDateTime> <quantityInHoursAndMinutes>1:00</quantityInHoursAndMinutes> <startTime>1970-01-01T11:00:00.000</startTime> <timeTypeName>Training days</timeTypeName> <endTime>1970-01-01T12:00:00.000</endTime> <startDate>2022-08-18T00:00:00.000</startDate> </EmployeeTimeSheetEntry> <EmployeeTimeSheetEntry> <lastModifiedDateTime>2022-11-09T07:25:56.000</lastModifiedDateTime> <quantityInHoursAndMinutes>2:00</quantityInHoursAndMinutes> <startTime>1970-01-01T15:00:00.000</startTime> <timeTypeName>Mission Hours</timeTypeName> <endTime>1970-01-01T17:00:00.000</endTime> <startDate>2022-08-18T00:00:00.000</startDate> </EmployeeTimeSheetEntry> </employeeTimeSheetEntry> <userId>2027</userId> </EmployeeTimeSheet><EmployeeTimeSheet> <approvalStatus>APPROVED</approvalStatus> <lastModifiedDateTime>2022-11-09T09:10:39.000</lastModifiedDateTime> <employeeTimeSheetEntry> <EmployeeTimeSheetEntry> <lastModifiedDateTime>2022-11-08T07:12:25.000</lastModifiedDateTime> <quantityInHoursAndMinutes>1:00</quantityInHoursAndMinutes> <startTime>1970-01-01T09:00:00.000</startTime> <timeTypeName>Mission Days</timeTypeName> <endTime>1970-01-01T10:00:00.000</endTime> <startDate>2022-08-14T00:00:00.000</startDate> </EmployeeTimeSheetEntry> <EmployeeTimeSheetEntry> <lastModifiedDateTime>2022-11-09T07:25:56.000</lastModifiedDateTime> <quantityInHoursAndMinutes>2:00</quantityInHoursAndMinutes> <startTime>1970-01-01T09:00:00.000</startTime> <timeTypeName>Mission Days</timeTypeName> <endTime>1970-01-01T11:00:00.000</endTime> <startDate>2022-08-18T00:00:00.000</startDate> </EmployeeTimeSheetEntry> <EmployeeTimeSheetEntry> <lastModifiedDateTime>2022-11-09T07:25:56.000</lastModifiedDateTime> <quantityInHoursAndMinutes>1:00</quantityInHoursAndMinutes> <startTime>1970-01-01T11:00:00.000</startTime> <timeTypeName>Training days</timeTypeName> <endTime>1970-01-01T12:00:00.000</endTime> <startDate>2022-08-18T00:00:00.000</startDate> </EmployeeTimeSheetEntry> <EmployeeTimeSheetEntry> <lastModifiedDateTime>2022-11-09T07:25:56.000</lastModifiedDateTime> <quantityInHoursAndMinutes>2:00</quantityInHoursAndMinutes> <startTime>1970-01-01T15:00:00.000</startTime> <timeTypeName>Mission Hours</timeTypeName> <endTime>1970-01-01T17:00:00.000</endTime> <startDate>2022-08-18T00:00:00.000</startDate> </EmployeeTimeSheetEntry> </employeeTimeSheetEntry> <userId>2029</userId></EmployeeTimeSheet> </EmployeeTimeSheet>
MartyMcCormick
Product and Topic Expert
Product and Topic Expert

Hi Syed

What data are you looking to combine from the payload and based on which value?

Thanks,

Marty

0 Kudos

Hi @marty.mccormick,

Thanks for your time.

Depending on the userId field if incoming payload as multiple entries i need to combine the timesheet entries and send it to Hana system.

multiple-weeks-community-payload-current.xml

multiple-weeks-community-payload-expected-output.xml

multiple-weeks-community-payload-current.xml this file has two 2027 entries(past week and current week this happen when approval is missed in last week and approved in Current week ) and single 2029 entry (current week).

Hope this helps,

Thanks in advance.


0 Kudos

Hi marty.mccormick,

Sorry for the delayed response i have attached the sample input and output payload,

Can you please have a look.

Thanks in advance,

MartyMcCormick
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Syed

I have used Groovyscript XMLSlurper in the past to accomplish this. Will the records come in sorted by userId field?

Thanks,
Marty

0 Kudos

Hi marty.mccormick no the records will not come in sorted by user id, but in the order they got approved.

depending on this field<lastModifiedDateTime>2022-11-09T09:10:39.000</lastModifiedDateTime> .

0 Kudos

Hi marty.mccormick

Can you please help me with groovy to achieve this?

Thanks in advance.

Accepted Solutions (0)

Answers (1)

Answers (1)

robertfels
Participant
0 Kudos
def xml = new XmlSlurper().parse(xmlString)

// Create a map to store the entries by lastModifiedDate
def entriesByDate = [:]

// Iterate over the EmployeeTimeSheetEntry elements
xml.'**'.EmployeeTimeSheetEntry.each { entry ->
    def date = entry.lastModifiedDateTime.text().split('T')[0]
    if (!entriesByDate[date]) {
        // If this date does not yet exist in the map, create a new list for it
        entriesByDate[date] = []
    }
    // Add the entry to the list for its lastModifiedDate
    entriesByDate[date] << entry
}

// Convert the entriesByDate map to a string
def output = entriesByDate.collect { date, entries ->
    "$date: ${entries.join(', ')}"
}.join('\n')

// Print the output string
println output