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: 
Jana_dK
Participant

Introduction


A few months ago, we noticed that some approvers tend to forget that they still had some open user tasks waiting for them. They don’t have the habit yet to check the inbox or their task center, as it’s new to them. This can cause some blocking issues during the flow of some business processes. Since there is no feature yet to notify users via mail that they have open user tasks waiting for action, we created an automation to send out mails to all the recipients.

Goal


We’re going to create a lightweight version of this automation and I’ll guide you through the steps to do this!

Prerequisites



  • Have the instance key of your SAP Build Process automation service


Create a destination for workflow


At first we have to create a destination for the workflow engine so we can gather all the open user tasks. If you have already done this, you can skip this step.

Create your destination with the following configuration:




Properties:

  • processautomation.enabled = true


 

To make use of this destination, you have to add it in your SAP Build lobby. Go to Settings and Destinations. There you can add your destination.



Create the automation


The goal of our automation is very simple: check if there are any open tasks (status ready or reserved), retrieve the recipients or groups attached to it, send out an email once a day to notify them that they have some open tasks waiting. We will do this by using some API’s you can find more about on the SAP API Business Accelerator Hub: https://api.sap.com/api/SPA_Workflow_Runtime/resource/User_Task_Instances

 

Environment variables


Create an environment variable of the type destination. That way you can use your workflow destination in an easy way to retrieve all the data.

 

Retrieve all user tasks with status ready


Use the activity Call webservice with destination to retrieve all the task instances which have the status ready. You can use this payload
var URL = "/v1/task-instances?status=READY"; 

var payload = {
'resolveBodyOnly' : true,
'method': 'GET',
'contentType': "application/json",
'responseType':'json',
'url': URL,
headers: {
'Content-Type': "application/json"
},
};
return payload;

You can expand this call with a lot more than only this parameter, based on your own needs. You can for example choose to only send mails to the user tasks with a high or very high priority, or when the dueDate is within the next week for example. Check the API Parameters for more information. In this example, I’m only going to check the ones that have status ready.

Read the emailadresses


To read out and gather all the emailadresses: add a new custom script activity with the result of your webservice call as an input parameter and a list of emailadresses as an output parameter. In my case we checked as well as the processor as the recipientslist.

You can use this code snippet:
var ReadyList = retrieveEmailadressesFromResult(UserTaskResultsReady);
ReadyList = removeDuplicates(ReadyList);

return ReadyList;

function removeDuplicates(arr) {
return arr.filter((item,
index) => arr.indexOf(item) === index);
}

function retrieveEmailadressesFromResult(Result){
var emailaddresses = [];

for( var i = 0 ; i < Result.length ; i++){
if( Result[i].processor != null ){
if (validateEmail(Result[i].processor) == true){
emailaddresses.push(Result[i].processor);
}
}

for ( var j = 0 ; j < Result[i].recipientUsers.length ; j++){
if( validateEmail(Result[i].recipientUsers[j]) == true){
emailaddresses.push(Result[i].recipientUsers[j]);
}
}
}

return emailaddresses;
}

function validateEmail (email) {
var re = /\S+@\S+\.\S+/;
return re.test(email);
}

 

For those who wonder, I used a simple regex to be sure that we’re dealing with an emailadress and not some wrong data. I’ve learned it the hard way that not everyone understands the concept of an ‘Emailaddress’ while adjusting business rules for approvers and sometimes some weird ‘emailadresses’ popped up. You can skip that function if you’re sure no one enters invalid emailadresses 😊

In the end your automation will look something like this


*Please add some try/catch error handling as I did not do it while creating this one for the blog 😉
**The read file is a local txt file I created in the automation with this filePath: irpa_core.enums.path.files + "/MailBody.txt"

 

Now you’re ready to go and send out an email to notify everyone that they still have open user tasks waiting for them to take action! We scheduled it every day, to check all ready and reserved user tasks. And additionally we created an other type of email when we saw that the priority was set to very high.

User groups in IAS


But what if you have used Recipient groups instead of Recipient Users? Then you can make use of the SCIM API's to retrieve the members of a certain group

Use this link to check out the API's available. We're going to make us of the Get group by ID and afterwards get the emailadress by looking up the id retrieved in the previous call.

 

First create a destination to your SCIM, your URL will be something like : https://<tenant>.accounts.ondemand.com/scim/
Retrieving all the members from your group can be done with the following very simple payload:





var URL = "/Groups/"+GroupID;

var payload = {
'resolveBodyOnly' : true,
'method': 'GET',
'url': URL,
};
return payload;





Add the activity Call Web Service with destination and read out all the members in this group.


var members = [];
var result = JSON.parse(ResultGroup);
for (var i = 0; i < result.members.length; i++){
members.push(result.members[i].value);
}

return members;

These member values are not emailadresses but their ID's. So if you want all the emailadresses, you will have to go over them one by one to retrieve the emailaddress specified in IAS:
var URL = "/Users/"+userid; //userid is your current member of the for each loop

var payload = {
'resolveBodyOnly' : true,
'method': 'GET',
'url': URL,
};
return payload;

var result = JSON.parse(ResultCall);
for(var i = 0; i < result.emails.length;i++){
emailadresslist.push(result.emails[i].value);
}


 

Conclusion


We know that reminders or notifications aren’t integrated yet, but it is on the roadmap to notify approvers via Task Center. We’re really waiting for this feature to be released! And in the meantime.. this automation does the trick to keep everyone notified!

Want to know more about my SAP Build Process Automation journeys and know hows? Follow me!

Questions, thoughts or comments? I’d love to hear them. Let’s get in touch!

 

 
Labels in this area