目前我正在尝试使用 S4/HANA SDK 来创建TimeSheetEntries
,但我遇到了一些问题。我收到这种异常:
Cannot cast class java.util.HashMap to class com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.manageworkforcetimesheet.TimeSheetDataFields
当我正在执行createTimeSheetEntry
方法时。难道我做错了什么?我附上了一个简单的例子,我是如何使用 API 的,如果你能指出我正确的方向,我将非常感谢你的努力。
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);
}