Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Adwait_Fadnavis
Discoverer
943

In the previous blog, my colleague and Senior Architect for SAP BTP, @mohit_bansal3 (Linkedin), explained the business drivers and expectations, detailing end-to-end scenarios utilizing SAP Build Process Automation-based SMTP Inbound.

In this  second blog post, I will walk you through the development steps in detail.

We have prepared the content for this series in three blogs, where we will be diving deep into Design, Development, and Testing.

As described in the previous blog post, we are using Google for external authentication. A similar approach is available for Microsoft 365-based development as well.

Now, let’s dive deep into the technical development process.

Development Process

Step 1: We have created an Action Project Workflow API which will be used to read workflow details and update the workflow status after approval or rejection.

SAP Build Process Automation: Action ProjectSAP Build Process Automation: Action Project

Step 2

As the next step, we will be creating an SAP BPA Automation Project as follows:

SAP Build Process Automation CockpitSAP Build Process Automation Cockpit

Step 3: Dependency Injection

As the next step, enable Google Authentication in the settings of the Automation Project. This step will activate Google Authentication, allowing the project to search and read Google emails.

Dependency InjectionDependency Injection

Additionally, add the dependency for the Action Project that we created earlier.

Dependency for the Action ProjectDependency for the Action Project

Step 4

We have also created a datatype that will hold the data and bind the workflow API for posting purposes.

Datatype: hold the data and bind the workflow APIDatatype: hold the data and bind the workflow API

Step 5

We are now ready to invoke Google Authentication and proceed with the development of the “Inbound SMTP.” Please refer to the flow chart below, which outlines the corresponding steps for enabling the necessary dependencies for Google Authentication within the project.

Adwait_Fadnavis_5-1732948604618.png

Step 6 : Search Unread Gmail email with Specific Subject

One of the most important activities in the process flow is to search for unread emails. We perform this search based on the subject line “Please Approve Request ID:”. All matching emails are then collected into an array called messageIdentifier.

Adwait_Fadnavis_6-1732948604622.png

Step 7 : Iterating the Email and Validations

The next step involves looping through all unread emails with a valid subject line relevant for processing. Here are the detailed considerations and steps:

  1. Loop Through Unread Emails: Iterate over all unread emails that match the subject line “Please Approve Request ID:”.

Loop Through Unread EmailsLoop Through Unread Emails

  1. Read and Save Emails: For each relevant email, read its content and save it in a local folder for further processing.

Adwait_Fadnavis_8-1732948604636.png

  1. Custom Script for Email Content Extraction: Write a custom JavaScript script to extract the necessary email content. The script should use the following input parametAdwait_Fadnavis_9-1732948604638.png
    • Subject: The subject line of the email.
    • From (Sender ID): The email address of the sender.
    • Body Content: The main content of the email.

 

 

 

var Req_id = Subject.split(":")[1];
var processedBody = Body.split("On")[0];

if (Body.substring(0,2) =="ok"  || Body.substring(0,8) =="Approved") {
    return {
        "Recipient": From,
        "Content": "Your request has been approved automatically",
        "approved": "yes"
    };
}
else if (Body.substring(0,2) =="no" || Body.substring(0,8) =="Rejected") {
    return {
        "Recipient": From,
        "Content": "Your request has been rejected automatically",
        "approved": "yes"
    };
}
else {
    return {
        "Recipient": From,
        "Content": "Your request has been Rejected automatically",
        "approved": "tbd"

    };
}

 

 

Adwait_Fadnavis_10-1732948604641.png

  1. Extract Workflow ID: Get the workflow ID (Request ID) from the subject line as a response from the email.

Extract Workflow IDExtract Workflow ID

Step 8

Now, fetch the workflow details using the valid Request ID. This step involves validating that the response is coming from a valid approver. This validation is crucial to ensure the integrity of the approval process. Below is a detailed explanation and a custom script to achieve this:

  1. Fetch Workflow Details: Use the Request ID to retrieve the workflow details from the system.

Adwait_Fadnavis_12-1732948604648.png

  1. Validate Approver: Ensure that the response is from a valid approver. This validation can be done by checking the sender’s email address against a list of authorized approvers.

Adwait_Fadnavis_13-1732948604652.png

  1. Custom Script for Validation: Write a custom JavaScript script to perform these tasks. The script will:
    • Fetch the workflow details using the Request ID.
    • Validate the sender’s email address.
    • Process the workflow details if the validation is successful.

 

 

for (var i = 0; i < TaskRecipient.length; i++) {
    if (From.includes(TaskRecipient[i])) {
        return true;
    }
}
return false;

 

 

Adwait_Fadnavis_14-1732948604655.png

Step 9

Handling Workflow Responses Now, we have a combination of three possible conditions to handle:Handling Workflow ResponsesHandling Workflow Responses

  1. Approve & Valid Approver: The workflow request is approved by an authorized approver.
  2. Reject & Valid Approver: The workflow request is rejected by an authorized approver.
  3. Response is Not Correct or Not a Valid Approver: The response is either incorrect or from an unauthorized approver.

Adwait_Fadnavis_16-1732948604662.png

Adwait_Fadnavis_17-1732948604666.png

Complete Flow Chart :  

Complete Flow ChartComplete Flow Chart

Here is a complete flow  that outlines the process for handling the three conditions mentioned above:

  1. Start
  2. Fetch Unread Emails
  3. For Each Email:
    • Check Subject Line: “Please Approve Request ID:”
    • Extract Request ID
    • Validate Approver
      • If Valid Approver:
        • Check Response:
          • If Approve: Update Workflow Status to “Approved”
          • If Reject: Update Workflow Status to “Rejected”
      • If Not Valid Approver: Handle Invalid Response
  4. End

This flow ensures that each email is processed correctly based on the response and the validity of the approver. By following these steps, you can maintain the integrity of the workflow process and ensure that only authorized actions are taken.

Step 10: Final Step

The final step in the process is to send a response email to all the parties involved. This ensures that everyone is informed about the status of the workflow request. Here’s how you can do it in detail:

Adwait_Fadnavis_19-1732948604672.png

  1. Compose the Response Email: Create the content of the email, including the status of the request (approved or rejected) and any relevant details.
  2. Identify Recipients: Determine the list of recipients who need to be notified. This typically includes the requester, approvers, and any other stakeholders.
  3. Send the Email: Use an email service or API to send the composed email to the identified recipients

In the upcoming blog post, @mohit_bansal3   will delve into the Testing Process flow in detail and provide valuable insights with a logical completion of this series.

Stay tuned for a comprehensive guide that will enhance your understanding and streamline your testing process.

 

1 Comment
priyankaG
Participant
0 Kudos

Hi  @Adwait_Fadnavis 

 

Interesting blog. Will this automation be running at a scheduled time. In that case isn't there a delay between the approver sending approve/reject mail and the workflow getting completed?? 

Labels in this area