Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Jonathan-Kong
Associate
Associate

JonathanKong_0-1710486356241.jpeg

Note: This blog serves as a technical walkthrough for the Automatic Service Order creation with SAP Build Process Automation and Generative AI blog.

 


SAP Build Process Automation

Our solution employs SAP Build Process Automation to log email data and attachments.

JonathanKong_1-1710486498231.png
Image 1: SAP Build Process Automation workflow

Essentially, the process automation is designed to monitor a dedicated inbox for service order requests sent by customers. Upon detecting a new service order request, it performs these actions:

  1. It saves the email attachments and content.
  2. It activates a custom script that packages the saved data into a JSON body. 
  3. It calls a Flask web service hosted on the Kyma runtime for processing, passing the above JSON body to it. 
  4. Once the web service has finished processing, it sends back an automated email response to the customer, updated with the service order number and status.

Following the processing of a request, the automation system continues to scan the inbox for additional emails. This iterative process repeats, ensuring no request is overlooked, and ceases only when there are no more relevant emails to process.

The custom script below shows an example of how you can package your payload to send over to the web service:

JonathanKong_2-1710486550893.png

Image 2: Custom script within the automated workflow

For a more in-depth example of developing a custom process automation workflow, check out this video done by my colleague here.

 

Custom Flask web service hosted on the SAP Kyma runtime

For your reference, the code for this custom flask web service can be found in this Github repository link

Upon receiving the JSON body from the above process automation, this custom Flask web service will then process the JSON body and post the desired outcome in JSON format into the S/4HANA system via two different API calls, which will be detailed below.

This web service makes use of the SAP AI Core, allowing us to utilize a variety of generative AI models in the Generative AI Hub.

For our solution, we thought that it was necessary to use two different AI models:

  1. A text-based LLM that is capable of extracting and summarizing important information out of the mail (which in our case, is Azure OpenAI gpt-4-32k)
  2. A large language-and-vision model that is capable of understanding and describing images (which in our case, is LLaVA-1.6)

Needless to say, these two models integrated seamlessly with our solution. 

 

Text processing using Azure OpenAI gpt-4-32k

This is an example of a service order request mail sent in by a customer:

JonathanKong_3-1710486647651.png
Image 3: Example service order request email

 

When handling a service order request sent by a customer, it's crucial to extract key details, such as the purchase date, model number, the problem as described by the customer, and the customer's contact information. The lack of uniformity in customer emails makes it challenging to use traditional methods like Regex for keyword extraction. This is where artificial intelligence becomes invaluable. It excels in understanding diverse text inputs and identifying essential information without the need for predefined patterns.

From a single email, AI enables us to accurately extract vital data, including:

  1. Model number
  2. Purchased date
  3. Customer's description of the problem
  4. Customer’s details
  5. Description of any attachments
  6. Any additional information that may be pertinent to the service request

Moreover, AI can leverage this information to generate a comprehensive problem description. When combined with image processing capabilities, this facilitates the creation of a detailed JSON payload.
This payload is then submitted to the S/4HANA Cloud, where the service order is generated (detailed at the bottom section of this blog).

For example, the following problem description is generated by AI (after passing to it the context of the mail and the images descriptions as well):

The customer has requested a service order for the following issue: damage to their shear, rendering it unusable, specifically a broken and detached handle grip, and a dislodged spring mechanism. The shear also began rusting within a month of use despite being advertised as waterproof. This damage considerably impacts the customer's ability to use the shear for its intended purpose. The customer mentioned that the shear was purchased on 27th December 2023, with the model number XKU00145. Given the unexpected nature of the damage and the fact that the shear should still be under warranty, the customer expects help in rectifying this situation through repair or replacement. The customer has also attached images documenting the specific damage (0987865.jpg). The image shows a pair of separated garden shears, a detached and possibly rusted spring, and signs of corrosion and wear on the metal parts. Due to these damages, the shears are not functional and appear to need repair or replacement to be usable again. The customer's contact number is +65 91112222.

 

Image processing using LLaVA-1.6

The above customer sends in an email with the following image attachment:

JonathanKong_4-1710486858513.png

Image 4: Example of an image attachment (take note of the file name)

 

JonathanKong_5-1710486891569.jpeg

Image 5: Example of an image attachment

The following description of the above image was generated using LLaVA-1.6:

The image shows a pair of garden shears that appear to be broken. The tool is meant to be a single piece, but it has been separated into two parts, indicating a failure. Specifically, the shears' handles have been detached from each other, and a spring which is likely supposed to provide tension for the pruning action is also detached and appears to be rusted. The metal parts of the tool show signs of corrosion and wear. Due to these damages, the shears are not functional in their current state and would require repair or replacement to be usable again.

Additionally, it renamed the file from 0987865.jpg to BrokenShears_RoronoaZoro_20240228213047.jpg.
Notice how a short description of the problem, the customer’s name, and a timestamp is concatenated to make the filename unique and easily identifiable:

JonathanKong_6-1710486978938.png

Image 6: Renaming of image attachment(s)

Also, multiple image attachments are also supported.

 

Creation of service order in the S/4HANA system

All the above data is then processed and passed on into a JSON payload (hint: we also used AI to format our JSON body😉, think adhering to maxLength text fields and potential loopholes that can be solved using AI), which is then submitted to the S/4HANA system through two separate APIs:

  1. Service Order Creation API (OData v2)
  2. Image Attachments API (OData v2)

As the name describes, the Service Order Creation API enables us to create service orders without having to manually create it on the S/4HANA system.

The Attachments API enables us to latch onto the business object (which is the service order created above), and uploads the images into the same service order. I have included the link above to both the API references. The APIs require CSRF tokens to be called, therefore a GET precedes every POST. The business object type to be used in the attachments API is BUS2000116.

The web service then passes the following example JSON payload into the S/4HANA system via the service creation API:

JonathanKong_7-1710487054665.png

Image 7: Example of the Service Order API JSON payload

 

Results

The service order is successfully created in the S/4HANA system!
The below image shows an excerpt of the service order:

JonathanKong_8-1710487105587.png

Image 8: An excerpt of the service order (Note that not the full service order is shown above, due to its large content)

 

Of course, if any of the fields are not filled in properly or if its properties are not respected, then the service creation will fail. I encourage you to read up the API reference for both the service order and attachments before getting started.

 

Solution Architecture – Service Order Automation

JonathanKong_9-1710487143718.png

Image 10: Solution architecture for automation scenario

If you’re interested in a high level overview of this solution, you can visit this blogAlso, if you're interested in exploring solutions like this or wish to learn more, feel free to reach out to me.

 

References

SAP Build Process Automation
SAP AI Core
SAP AI Core service guide
Generative AI @ SAP
Service Order documentation
Generative AI hub sdk
Service Order Creation API (OData v2)
Image Attachments API (OData v2)