0

How to create parent entity along with its subentity using S/4 Hana Cloud SDK,and Cloud SDK What should I do to resolve the below error?

“errordetails”: [

{
“code”: “API_PRD_MSG/004”,
“message”: “Provide atleast one description for the product.”,
“propertyref”: “”,
“severity”: “error”,
“target”: “”
}
]

How can I modify my code?

Update

This deep create blog [https://blogs.sap.com/2017/12/07/step-20-with-s4hana-cloud-sdk-create-and-deep-insert-with-the-virtual-data-model-for-odata/][1] is achieved using servlets(where HttpRequestServlet Class is used to get the parameters) but I am using Cloud SDK's @Create annotation and CreateRequest Class to get the payload..

I am able to get Parent entity data in toParent object Product toParent = new ModelMapper().map(req.getMapData(), Product.class); How to get subentity data(Here ProductDescription) which is being passed in payload to deep insert both Parent and child entity data?

Payload which I am passing in postman:

{
  "Product" : "BALL",
    "ProductType" : "ZHLB",
    "CrossPlantStatus" : "",
    "CrossPlantStatusValidityDate" : null,
    "CreationDate" : "\/Date(1499731200000)\/",
    "CreatedByUser" : "11279380",
    "LastChangeDate" : "\/Date(1550448000000)\/",
    "LastChangedByUser" : "HWV87616",
    "IsMarkedForDeletion" : false,
    "ProductOldID" : "",
    "GrossWeight" : "0.000",
    "PurchaseOrderQuantityUnit" : "",
    "SourceOfSupply" : "",
    "WeightUnit" : "KG",
    "NetWeight" : "0.000",
    "CountryOfOrigin" : "",
    "CompetitorID" : "",
    "ProductGroup" : "01",
    "BaseUnit" : "EA",
    "ItemCategoryGroup" : "",
    "ProductHierarchy" : "",
    "Division" : "",
    "VarblPurOrdUnitIsActive" : "",
    "VolumeUnit" : "",
    "MaterialVolume" : "0.000",
    "ANPCode" : "0",
    "Brand" : "",
    "ProcurementRule" : "",
    "ValidityStartDate" : null,
    "LowLevelCode" : "",
    "ProdNoInGenProdInPrepackProd" : "",
    "SerialIdentifierAssgmtProfile" : "",
    "SizeOrDimensionText" : "",
    "IndustryStandardName" : "",
    "ProductStandardID" : "",
    "InternationalArticleNumberCat" : "",
    "ProductIsConfigurable" : false,
    "IsBatchManagementRequired" : false,
    "ExternalProductGroup" : "",
    "CrossPlantConfigurableProduct" : "",
    "SerialNoExplicitnessLevel" : "",   
    "ManufacturerPartProfile" : "",
    "ChangeNumber" : "",
    "MaterialRevisionLevel" : "",
    "HandlingIndicator" : "",
    "WarehouseProductGroup" : "",
    "WarehouseStorageCondition" : "",
    "StandardHandlingUnitType" : "",
    "SerialNumberProfile" : "",
    "AdjustmentProfile" : "",
    "PreferredUnitOfMeasure" : "",
    "IsPilferable" : false,
    "IsRelevantForHzdsSubstances" : false,
    "QuarantinePeriod" : "0",
    "TimeUnitForQuarantinePeriod" : "",
    "QualityInspectionGroup" : "",
    "AuthorizationGroup" : "",
    "HandlingUnitType" : "",
    "HasVariableTareWeight" : false,
    "MaximumPackagingLength" : "0.000",
    "MaximumPackagingWidth" : "0.000",
    "MaximumPackagingHeight" : "0.000",
  "to_Description": {
    "results": [
     {
        "Product" : "BALL",
        "Language" : "EN",
        "ProductDescription" : "Pipes for machines"
      }
    ]
  }
}

Create Code which is being used

@Create(serviceName = "ProductService",Entity="Products")
    public CreateResponse create(CreateRequest req) throws ODataException {
    Product toCreate = new ModelMapper().map(req.getMapData(), Product.class);
    Product created = new DefaultProductMasterService().createProduct(toCreate)
                    .execute(new ErpConfigContext("K4XS4SDKDest"));
                new DefaultProductMasterService().createProductDescription(toCreateDescription).asChildOf(toCreate, Product.TO_DESCRIPTION);
            return CreateResponse.setSuccess().setData(created).response();
Meenakshi
  • 31
  • 3
  • Are there any specific issues you have or errors you see? I suggest to read into this [blog post](https://blogs.sap.com/2017/12/07/step-20-with-s4hana-cloud-sdk-create-and-deep-insert-with-the-virtual-data-model-for-odata/) which describes in detail how you can execute a "deep create". – Christoph Schubert Mar 14 '19 at 08:03
  • Thanks for your instant reply.I have edited my question for your perusal.Please help. – Meenakshi Mar 14 '19 at 09:39
  • Okay, so did I understand you question correctly: You sent the given payload to the create OData endpoint of your application. Therein you want to extract the parent object (`Product`) as well as a child object (`ProductDescription`). The `Product` case works without a problem, but you don't know where to get the `toCreateDescription` in your example from. – Christoph Schubert Mar 14 '19 at 10:23
  • Yes exactly.That is my problem..don't know where to get the toCreateDescription.Please help. – Meenakshi Mar 14 '19 at 10:30
  • This is an very important issue to get solved for our client..Kindly help immediately. – Meenakshi Mar 18 '19 at 10:06
  • Have you tried my proposed solution to your duplicate ticket...? https://stackoverflow.com/a/56322653/9350514 To which endpoint to you send the "payload which [you are] passing in postman" - the application or directly the OData service endpoint? – Alexander Dümont Jun 03 '19 at 07:56
  • 2
    Either way, the `"to_Description"` really should be an array and not an object. The second service call shouldn't be required. Have you checked whether instance `Product toCreate` actually contains a description? You created the object yourself through deserialization. – Alexander Dümont Jun 03 '19 at 08:08

0 Answers0