Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member666537
Participant
6,283

In this blog post I would like to share how you can create sales order in SAP System using SAP Intelligent Robotic Process Automation, aka, SAP iRPA. But,before we start building our bots, we need to get our system ready for this. Following this great blog post from vijay.sharma4 I have my set up ready and running.



What we are trying to do?


Create a sales order in SAP System based on the purchase order and that purchase order will be received from mail attachment (excel) by customer. RPA Bot will follow below steps-

  • Fetch the purchase order mail from outlook and download the attachment and save it in the project folder

  • Read the mail, extract the data in some variables

  • Open the SAP GUI Application, select the system and then logon to system with credentials

  • Enter T Code in SAP Easy Access for creating sales order

  • Enter all the required data, which will need to create sales order


Let’s Begin


Now our system is ready to build bot. Open the desktop studio and follow the below steps-

Step-1 Create new project

  • Goto File > Create New Project or press “Ctrl + N




  • Fill in the mandatory details in the pop-up, I have maintained below details for my project and then click on save.



Step-2 Add Excel and Outlook library script

  • Open the script tab from context menu and right click on script area then select Include library script.





  • Check on excel and outlook integration and save it.



Step-3 Create New Application and add pages to it

  • Click on applications from context menu and then Right click on Application panel and click on Add New Application





  • Select UIAutomation in the technology and it will display list of all the Windows application running under Applications, select SAP GUI Logon as shown below and click on Save and Capture Page.





  • Capture page popup will open, select the page from the selected application. and then save and capture it.





  • Selected page will be displayed inside your application as shown below





  • Right click on some data under Capture Data section and click on “Add to Criteria”. Criteria helps your bot to identify page. As soon as you add the criteria, page will turn into Green as shown below






  • Now let’s capture a new page for logon screen, before capturing the page please make sure you open next screen on SAP GUI Application

  • To capture new right-click on your application and select Capture a New Page





  • For capturing all next pages we will choose technology as SAP GUI.

  • Likewise we will capture all the pages which are required to create a sales order. Add the criteria on the pages for the required data.



Step-3 Create Workflow

  • Select workflow under context menu. Right click on Global and click on New Workflow.





  • Enter the workflow name and click on save, I will name it as SAPLogon



Step-4 Add Activities in your Workflow

  • The first activity that you need to add in your workflow is a Custom activity so you can use the functions in the Outlook library. You can give a name and a description for this activity, so you can distinguish better its purpose. I will name mine “saveAttachments”.





  • Before you can continue with the rest of the functionalities you need to build your project. This way the script for the workflow will be generated and we can enhance it. Open the script generated by your workflow ( it will have the same name ). Search for your custom activity and step by their name. You can write the rest of the logic in this step. Update SENDER EMAIL ADDRESS, SUBJECT OF YOUR MAIL and PROJECT FOLDER PATH in the below code


GLOBAL.step({ saveAttachments: function(ev, sc, st) {
var rootData = sc.data;
ctx.workflow('SAPLogon', '4830c49e-2646-41aa-a683-7624c75e8c9c') ;
// saveAttachments
ctx.outlook.init();
var mails = [];
var i, j, path, filename, attachments, noAttachments;

// Resets the working mails list.
ctx.outlook.mail.resetMailCollection();

// Search the body of email for a keyword. Other criteria are also available.
ctx.outlook.mail.searchByCriteria({
fromEmail: "SENDER EMAIL ADDRESS",
subject: "SUBJECT OF YOUR MAIL",
hasAttachment: 1,
dontThrowExceptionIfNoMailFound: true
});

// Get the list of mail information for the mails that fit the criteria.
mails = ctx.outlook.mail.getFilteredTable();

// Build the working mails list by retrieving each mail.

if (mails.length) {
for (i = 0; i < mails.length; i++) {
ctx.outlook.mail.retrieveMail({
EntryID: mails[i]['EntryID'],
StoreID: mails[i]['StoreID']
});
}

// Display some info about each email.
ctx.log("---------------------------------------------------------");
for (i = 0; i < ctx.outlook.mail.getCollectionLength(); i++) {
ctx.log("Mail no: " + i);
ctx.log("From: " + mails[i]['Sender']);
ctx.log("Subject: " + ctx.outlook.mail.getSubject(i));
ctx.log("---------------------------------------------------------");

// Here we start the procedure of downloading the attachments in the email (if they exist).
// Get the number of attachments for each email.
noAttachments = ctx.outlook.mail.getAttachmentsCount(i);
// Get the name of the attachments.
attachments = ctx.outlook.mail.getAttachmentsName(i);

// Download the attachments if they exist.
if (noAttachments > 0) {
// Save each attachment separately.
for (j = 0; j < noAttachments; j++) {
filename = attachments[j];
path = "PROJECT FOLDER PATH" + filename;
ctx.outlook.mail.attachmentSave(i, path, {
AttachmentName: filename
});
ctx.log('File downloaded: ' + filename);
}
}
}
}

// Ends “Microsoft Outlook” application.
ctx.outlook.end();

sc.endStep(); // Sequence
return;
}});


  • In the context menu, right click on the folder SAPLogon760Data that will be automatically create when you capture application pages data, click on create item and then create three variables in which mail attachment values will be stored.





  • Drag and drop the sequence activity.





  • Now double click the sequence and we will add our our steps from excel library. The first step is to initialize the excel and open the sheet. Give the project folder path which you had given earlier for downloading attachment, to open the excel sheet





  • Next steps are for getting values from downloaded file. Drag and drop Get one value activity three times to getting three values. Add the variable by selecting context path. And then define the row and column for respective item. Do not worry about the code it will generate automatically when you will save it.





  • Now we want to start our SAP GUI application so for that we drag and drop Start Application under Activities to our workflow





  • Now go to Pages beside Activities, it will display all the pages you have created in your application as below





  • Drag and drop first page to the workflow and connect it to Start application





  • Double-click on your page inside the workflow to edit the Activities. You will be navigated to the page activities section as shown below. Drag and drop Click activity under Item and attach it to system which was highlighted when we created page in our application and click on Save or press Ctrl + S





  • Similarly you will have to add all the pages. Drag and drop all the activities which are required to automate the process and attach these activities to the highlighted part.





  • In this scenario you will have to use some activities like Double click, click, set and keystroke for page. Keystroke will be Enter in our case. So for this, first select the page and write key sequence as e.SAPScripting.key._Enter_



Step-5 Execute the bot

  • To execute our bot we first need to build and then run our project. Once Build is success, you will get message as below





  • Now click on Play icon or press F5 to debug the script. You will get the below messages in Desktop Debugger





  • Now right-click on Desktop Agent and click your workflow



Conclusion

This blog post should help you to understand the use of the ‘Outlook Library’, how to recursively save email attachments from selected emails, read excel sheet from specified folder, add application and capture application pages and add all these pages in the workflow.
42 Comments
Labels in this area