Currently I am trying to use the S4/HANA SDK to create TimeSheetEntries
but I have encountered some problems.
I am receiving this kind of exception:
Cannot cast class java.util.HashMap to class com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.manageworkforcetimesheet.TimeSheetDataFields
while I am executing createTimeSheetEntry
method.
Am I doing something wrong? I attached a simple example how I am using the API and if you could point me in the right direction I would really appreciate your efforts.
public void createHardCodedEntry() throws ODataException {
Calendar c = Calendar.getInstance();
c.set(2017, Calendar.DECEMBER, Calendar.MONDAY);
TimeSheetEntry entry = TimeSheetEntry.builder().timeSheetDate(c)
//.timeSheetIsExecutedInTestRun(false)
//.timeSheetIsReleasedOnSave(true)
.timeSheetOperation("C")
.timeSheetStatus("20")
.personWorkAgreementExternalID("ADMINISTRATOR")
.personWorkAgreement("50000033")
.companyCode("1010")
.timeSheetDataFields(TimeSheetDataFields.builder()
.timeSheetTaskLevel("NONE")
.timeSheetTaskType("ADMI")
.recordedHours(new BigDecimal(12))
.recordedQuantity(new BigDecimal(12))
.timeSheetTaskComponent("WORK")
.controllingArea("A000")
.hoursUnitOfMeasure("H")
.build())
.build();
ErpConfigContext erpConfigContext = new ErpConfigContext("S4HANA_CLOUD"); //this is the name of the destination configured in SCP
TimeSheetEntry savedEntry = new DefaultManageWorkforceTimesheetService().createTimeSheetEntry(entry).execute(erpConfigContext);
}
This problem of failing structured field deserialization has been fixed in the latest version of SAP S/4HANA Cloud SDK. To update, please find the <dependencyManagement>
in your root Maven POM file and increment the <version>
for sdk-bom
to 1.9.2
<?xml version='1.0' encoding='utf-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- ... -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sap.cloud.s4hana</groupId>
<artifactId>sdk-bom</artifactId>
<version>1.9.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- ... -->
</project>
During compilation Maven will automatically fetch the updated version from the Maven Central Repository. Simply run mvn clean install
in your local working directory to make sure the new dependencies are propagated to all of your project modules.