Feature:

This Blog is to give an insight into ODATA usage for Attachments feature in S/4HANA cloud edition 2008CE.

Reference Links:

https://help.sap.com/viewer/adbae5bcd5994f159bf2847a11397b61/2005.500/en-US/1209e1ca48c04105a08ab2314887f4ad.html

https://help.sap.com/viewer/a630d57fc5004c6383e7a81efee7a8bb/2005.500/en-US/e7ff65b0c2c34652995745c9416edc5e.html

Attachments Functionality:

For Service order and confirmations, attachment service is enabled as of 2008CE in ODATA API’s which provides users the ability to create, delete and download attachments.

The ODATA Service feature for attachment is available for the below Objects:

1)    Service Order Header

2)    Service Order Item

3)    Service Confirmation Item

 

This Blog gives a reference to prospective users of the ODATA API’s as to how they can create, download and delete Attachments in Service Orders and Confirmations.

·       Variant 1: Create Attachments

·       Variant 2: Read Attachment details(metadata)

·       Variant 3: Download Attachments

·       Variant 3: Delete Attachments

ODATA for consumption:

For more technical details on the ODATA API’s, check SAP help link below -https://help.sap.com/viewer/DRAFT/6d57d4ab71e5408581e2018320a0ce49/2008.500/en-US/ddfe570e96c84075b2ff3e5b1be9714b.html

 

Variant 1: Create Attachments

Service Order Header  

Initially, Create Service order and then add attachment to it.

Step1: Creating Service order

Sample payload to run ODATA API_SERVICE_ORDER_SRV for service order.

Request type: Post, 201 is return code if request is successful, 4xx and 5xx series if request fails

 

{"ServiceOrderType":"SVO1",

 "ServiceOrderDescription":"Testing Transaction currency Odata 2",

 "RequestedServiceStartDateTime":"\/Date(1586754739019)\/",

 "RequestedServiceEndDateTime":"\/Date(1587013939019)\/",

 "SalesOrganization":"1710",

 "DistributionChannel":"10",

 "Division":"00",

 "SalesOffice":"",

 "SalesGroup":"",

 "SoldToParty":"17100014",

 "ServiceOrderIsReleased":" ",

 "TransactionCurrency": "USD",

 "RespyMgmtServiceTeam":"50001475",

"to_Item”: [{"Product":"SRV_01","Quantity":"1","QuantityUnit":"HR","BillableControl":"","ServiceOrderItemIsReleased":" "}]}

In response body service order details can be used to create attachments.

Step2: Creating Attachement for Service order

Sample payload to run ODATA API_CV_ATTACHMENT_SRV for create attachment in service order.

Request type: Post, 201 is return code if request successful, 4xx and 5xx series if request fails

 

In Request header {

Content-Type:                      “image/png” <File type>

Slug:                                     “Test File.png” <File Name>

LinkedSAPObjectKey:          “8000025235” <Service Order id/item uuid/confirmation uuid>

BusinessObjectTypeName:  “BUS2000116” <Business object key>

X-CSRF-Token:                     <Authorization key from odata>

}

 

In Request Body, please select attachment file and Post request. 201 is return code if request is successful.

Different Content-types examples:

·       image/png (PNG file)

·       image/jpg (jpg file)

·       application/pdf (PDF file)

·       text/plain (text file)

·       application/vnd.openxmlformats-officedocument.wordprocessingml.document (word document docx extension)

Service Order Items

Step1: Get Service order Item details

Item details (like UUID and Business object) can be retrieved using ODATA API_SERVICE_ORDER_SRV (<Service Order>)/to_items Get request.

In response body items details can be used to create attachments in service order items.

Step2: Creating Attachment for Service order Items

Sample payload to run ODATA API_CV_ATTACHMENT_SRV for create attachment in service order.

Request type: Post, 201 is return code if request successful, 4xx and 5xx series if request failed

 

In Request header {

Content-Type:                      “image/png” <File type>

Slug:                                     “Test File.png” <File Name>

LinkedSAPObjectKey:          “0894EF4576511EE9BC90C2B725909402” <Service Order item uuid >

BusinessObjectTypeName:  “BUS2000140” <Business object key>

X-CSRF-Token:                     <Authorization key from odata>

}

 

In Request Body Please select attachment file and Post request. 201 is return code if request successful.

 

 

Service Confirmation items.

Initially, Create Service Confirmation and then add attachment to it.

Step1: Create Confirmation items:

Sample payload to run ODATA API_SERVICE_CONFIRMATION_SRV to create confirmation

Request type: Post, 201 is return code if request successful, 400 and 500 series if request failed

{

 "ServiceConfirmationType":"SVC1",

 "ServiceConfirmationDescription":"",

 "RequestedServiceStartDateTime":"\/Date(1593685721584)\/",

 "RequestedServiceEndDateTime":"\/Date(1593944921584)\/",

 "ReferenceServiceOrder":"8000599411",

 "ServiceConfirmationIsFinal":"N",

 "SoldToParty":"17100004",

 "RespyMgmtServiceTeam":"50001702",

 "to_Item":[ {"ServiceConfirmationItem":"010",

             "Product":"SRV_01",

             "Quantity":"2",

             "QuantityUnit":"HR",

             "BillableControl":"",

             "ExecutingServiceEmployee":"9980000857",

             "RespyMgmtServiceTeam":"50001702",

             "ReferenceServiceOrder":"8000599411",

             "ReferenceServiceOrderItem":"000020",

             "ActualServiceDuration":"2.000",

             "ActualServiceDurationUnit":"HR",

             "ParentServiceConfItem":"010"}]

}

In response body Confirmation items details can be used to create attachments.

Step2: Creating Attachment for Confirmation items

Sample payload to run ODATA API_CV_ATTACHMENT_SRV for create attachment in Confirmation items.

Request type: Post, 201 is return code if request successful, 4xx and 5xx series if request failed

In Request header {

Content-Type:                      “image/png” <File type>

Slug:                                     “Test File.png” <File Name>

LinkedSAPObjectKey:          “0894EF4587211EE9AAA6D56C2A1AED43” <confirmation item uuid>

BusinessObjectTypeName:  “BUS2000116” <Business object key>

X-CSRF-Token:                     <Authorization key from odata>

}

 

In Request Body Please select attachment file and Post request. 201 is return code if request successful.

 

Variant 2:  Read Attachments

Before reading attachments need to get service order, items and confirmation item details

Header: Details (like Service Order and Business object) can be retrieved using ODATA API_SERVICE_ORDER_SRV (<Service Order>)

Items: Details (like UUID and Business object) can be retrieved using ODATA API_SERVICE_ORDER_SRV (<Service Order>)/to_items

Confirmation Items: Details (like UUID and Business object) can be retrieved using ODATA API_SERVICE_ORDER_SRV (<Service Order>)/to_Confirmations

 

Sample payload to run ODATA API_CV_ATTACHMENT_SRV to read attachment details.

ODATA Action to get attachments: GetAllOriginals

Request type: Get, 200 is return code if request successful, 4xx and 5xx series if request failed

In Request header {

BusinessObjectTypeName: %27BUS2000116%27   <Business Object>

LinkedSAPObjectKey:        %278000025235%27 < Service order or item UUID or confirmation item UUID>

}

In response body attachment details can be found. Below field values will be used to download and delete attachments.

·       DocumentInfoRecordDocType

·       DocumentInfoRecordDocNumber

·       LogicalDocument

·       ArchiveDocumentID

·       LinkedSAPObjectKey

·       BusinessObjectTypeName

 

Variant 3: Download Attachments

Before Download need to read attachment details, please refer to Variant 2.

Sample payload to run ODATA API_CV_ATTACHMENT_SRV to download attachment details.

Odata Action: AttachmentContentSet

Request type: Get, 200 is return code if request successful, 4xx and 5xx series if request failed

In Request header (

DocumentInfoRecordDocType:      'GOS'

DocumentInfoRecordDocNumber: 'EXT45000000001222'

DocumentInfoRecordDocPart:       ' '

DocumentInfoRecordDocVersion:  ' '

LogicalDocument:                          '506B4BC345F41EEA9FC0D4ED36A2FC16'

ArchiveDocumentID:                      '506B4BC345F41EEA9FC0D4ED36A31C16'

ArchiveDocumentID:                      '506B4BC345F41EEA9FC0D4ED36A31C16'

BusinessObjectTypeName:            'BUS2000116'

) /$value

From response body tab user can download attachment.

From read attachments variant user can details above details.

 

Variant 4: Delete Attachments

Before Delete need to read attachment details, please refer to Variant 2.

Sample payload to run ODATA API_CV_ATTACHMENT_SRV to delete attachment details.

ODATA Action: AttachmentContentSet

Request type: Delete, 201 is return code if request successful, 4xx and 5xx series if request failed

In Request header (

DocumentInfoRecordDocType:      'GOS'

DocumentInfoRecordDocNumber: 'EXT45000000001222'

DocumentInfoRecordDocPart:       ' '

DocumentInfoRecordDocVersion:  ' '

LogicalDocument:                          '506B4BC345F41EEA9FC0D4ED36A2FC16'

ArchiveDocumentID:                      '506B4BC345F41EEA9FC0D4ED36A31C16'

ArchiveDocumentID:                      '506B4BC345F41EEA9FC0D4ED36A31C16'

BusinessObjectTypeName:            'BUS2000116'

)

From read attachments variant user can details above details. Once delete is successful user can check using read attachments GET request.