SUCCESSFACTOR Execution Manager Logging Using Cloud Platform Integration (CPI) Middleware

Estimated read time 17 min read

Introduction: This blog post explains you how to log the Interface execution details in Execution Manager in SuccessFactors using CPI. You can monitor easily all the interfaces at Execution Manager with different Status like Completed, Failed, In Progress.

We created two very simple IFlows in CPI –

Here is how our Main IFlow looks like:

Step 1: Firstly, we use ‘Content Modifier’ to set the Properties to show the Iflow names with its current status in Execution Manager in SuccessFactors.

Action

Name

Source Type

Source Value

Data Type

Create

iflowName

Expression

${camelid}

java.lang.String

Create

messageId

Header

SAP_MessageProcessingLogID

java.lang.String

Create

iflowStatus

Constant

START

 

 

Step 2: (Set EM control variables) – Now we used ‘Groovy Script’ to set suitable time zone with the Iflow Names.

 

/*
This groovy script is used to set Property for EM handler
*/
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.time.ZonedDateTime;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.TimeZone;

def Message processData(Message message) {

// Retrieve integration parameters from properties
properties = message.getProperties();

// convert to HKT timezone
def timeZone = TimeZone.getTimeZone(‘HKT’);

// set today and tomorrow date to HKT timezone
def dateFormat = “yyyy-MM-dd”;

def newTodayDate = new Date();
def today = newTodayDate.format(dateFormat, timeZone);
message.setHeader(“today”, today);

//add for EM handler start
def currentTime = newTodayDate.format(“yyyy-MM-dd’T’HH:mm:ss”).toString()

//get current iflow name
String iflowName = properties.get(“iflowName”);
message.setProperty(“iflowName”, iflowName);

// set processName with time

message.setProperty(“processName”, iflowName + ” ” + currentTime);

//add for EM handler end
return message;
}

 

Step 3: In this step we used ‘Process call’ to call the Local Integration Process (Send Event to Execution Manager).

Note: To continue with the Local Integration Process (Send Event to Execution Manager) steps, kindly read from Step No. 8 to understand all the steps and working of Local Integration Process.

Step 4: Here we used ‘Request Reply’ to fetch some field’s data from SuccessFactors based on the query.
Query- $select=userId,city,gender,firstName,lastName&$top=50

Step 5: Now we created one .xsd file and used Message Mapping to map these fields with the same fields fetched from the SuccessFactors in Previous step. All the fields are mapped using One to One mapping.

Step 6: (EM END) – In this step we wrote a groovy script to set the Iflow status as ‘END’ which will be sent to the Execution Manager in SuccessFactors.

 

/* Refer the link below to learn more about the use cases of script –
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/148851bf8192412cba1f9d2c17f4bd25.html
If you want to know more about the SCRIPT APIs, refer the link below –
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en-US/index.html */
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
message.setBody(“”);
message.setProperty(“iflowStatus”, “END”);
return message;
}

 

Step 7: In this step we again used ‘Process Call’ to call the Local Integration Process (Send Event to Execution Manager).

#Now we will configure the Local Integration Process ‘Send Event to Execution Manager’ –

#Below is how the ‘Send Event to Execution Manager’ Flow looks like –

Step 8: We wrote a groovy script here with the name ‘EM Event Formatter’. In this step first we get all the events in the script with message name, Id and status then made some cases based on there execution status like START, FAILED, END.

 

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.util.XmlSlurper;
import groovy.xml.XmlUtil;

def Message processData(Message message) {

//define the initial format and property
def text = ”’
<EMEvent>
<process>
<EMMonitoredProcess>
<processType>INTEGRATION</processType>
</EMMonitoredProcess>
</process>
</EMEvent>
”’
def EMEvent = new XmlSlurper().parseText(text)
def props = message.getProperties();

def eventNameS;
def eventDescriptionS;
def eventTypeS;
def body = “”;

String messageId = props.get(“messageId”) as String
String processName = props.get(“processName”) as String
String iflowName = props.get(“iflowName”) as String
String iflowStatus = props.get(“iflowStatus”) as String

//define the EM status
switch(iflowStatus){
case ‘START’:
eventNameS = “iflow start”
eventDescriptionS = “iflow start”
eventTypeS = “START”
break;
case ‘END’:
eventNameS = “iflow end”
eventDescriptionS = “iflow end”
eventTypeS = “END”
break;
case ‘FAILED’:
eventNameS = “iflow failed”
String exceptionMessage = props.get(“CamelExceptionCaught”) as String
eventDescriptionS = exceptionMessage
eventTypeS = “FAILED”
break;
default:
eventNameS = “”
eventDescriptionS = “”
eventTypeS = “”
}

Date currentdate = new Date();
def currentTime = currentdate.format(“yyyy-MM-dd’T’HH:mm:ss.SSS”).toString()

//define the request event, content display in process event, every message could have multiple events
EMEvent.appendNode {
eventDescription(eventDescriptionS)
eventTime(currentTime)
eventName(eventNameS)
eventType(eventTypeS)

}

//define the request process, the process should be unique for every iflow process message
EMEvent.process.EMMonitoredProcess.appendNode {
processDefinitionId(iflowName)
processDefinitionName(iflowName)
processInstanceId(messageId)
processInstanceName(processName)
}

body = XmlUtil.serialize(EMEvent).substring(38)

body = “<EMEvent>” + body + “</EMEvent>”
message.setBody(body);
return message;
}

 

Step 9: Here we use the ‘Process Call’ with name EMHandler. It will call another IFlow we created with the name ‘ExecutionManagerProcessDirect’.

Note: To continue with the Another Integration (ExecutionManagerProcessDirect) steps, kindly read from Step No. 16 to understand all the steps and working of our 2nd Integration.

Step 10: We wrote groovy script here to set the body of the message as empty so that after 1st Event process completion it will continue with the rest of the process through the main flow for other events.

 

def Message processData(Message message) {
//Body
def body =””;
message.setBody(body);
return message;
}

 

 

 

Step 11: Now we created an Exception Subprocess in our main Iflow which would call another Local Integration process ‘Exception Error Handling’ if any error occurred during main Integration process.

 

Step 12: In this step we will write all the description in the body of the ‘Content Modifier’ which needs to be captured during the Interface failure.

Content Modifier Body – 

 

Please be informed that a technical issue occurred in the interface. The following information below may help to troubleshoot.

— Integration parameters —
Last run date: ${property.LSRD}

— Exception Message —
${exception.message}
— End of Exception Message —

— Stack trace —
${exception.stacktrace}
— End of Stack trace —

 

Step 13: In this step we set the value of the IFlow status as ‘FAILED’ using below ‘groovy Script’.Groovy Script 5 – (EM Exception) –

 

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
message.setBody(“”);
message.setProperty(“iflowStatus”, “FAILED”);
return message;
}

/* Refer the link below to learn more about the use cases of script.
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/148851bf8192412cba1f9d2c17f4bd25.html
If you want to know more about the SCRIPT APIs, refer the link below
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en-US/index.html */

 

Step 14: In this step we again used the ‘Process Call’ to call the same Local Integration process ‘Send Event to Execution Manager’ so that the status of the interface can be updated as ‘FAILED’ in Execution Manger.


Step 15:
(EM END) – In this step we again wrote the same groovy script to set the Iflow status as ‘END’.

Note: We have to set the status of an Iflow as ‘END’ after every process completion (START,FAILED) otherwise in SuccessFactors you will always see the status of the same IFlow as ‘In Progress’. It will only complete when you will use the ‘END’ Event after every process completion.

 

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
message.setBody(“”);
message.setProperty(“iflowStatus”, “END”);
return message;
}

/* Refer the link below to learn more about the use cases of script –
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/148851bf8192412cba1f9d2c17f4bd25.html
If you want to know more about the SCRIPT APIs, refer the link below –
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en-US/index.html */

 

Step 16: (Send EM Event) – In this step we again used the Process direct to call the same Local Integration process ‘Send Event to Execution Manager’ which we called in previous steps as well so that it can update the status of the interface as ‘END’ in Execution manager.

#Below is our 2nd IFlow named ‘ExecutionManagerProcessDirect’ –

 

Step 17: In this step all the data comes here through ProcessDirect from our Main IFlow. After that we wrote a groovy script to set the payload and dataStoreId as Property.

 

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.util.XmlSlurper;

def Message processData(Message message) {
//Body
def body = message.getBody(java.lang.String) as String;
def input = new XmlSlurper().parseText(body);

def dataStoreId = input.EMEvent.process.EMMonitoredProcess.processInstanceId.text() + ” ” + input.EMEvent.eventTime.text();

message.setProperty(“payload”,body);
message.setProperty(“dataStoreId”, dataStoreId);
return message;
}

 

Step 18: In this step we performed the Upsert call to SuccessFactors and update all the required details in Execution Manager. To perform this action, we use ‘EMEvent’ Entity of SuccessFactors.

Step 19: In this step we are using ‘Content Modifier’ in ‘Exception Subprocess’ to store all the data in case of any failure occurs during Interface execution and Interface’s status was not updated at SF due to this.

Step 20: Now we stored the same data in our CPI Data stores in case we need to use the same.

 

Monitoring in Execution Manger –

Now you need to deploy both the Iflows and check the monitor the executions in execution manager at SuccessFactors. Please check below screenshots about how it looks like at SF –

 

 

Thank you for reading this Blog.

 

​ Introduction: This blog post explains you how to log the Interface execution details in Execution Manager in SuccessFactors using CPI. You can monitor easily all the interfaces at Execution Manager with different Status like Completed, Failed, In Progress.We created two very simple IFlows in CPI -Here is how our Main IFlow looks like:Step 1: Firstly, we use ‘Content Modifier’ to set the Properties to show the Iflow names with its current status in Execution Manager in SuccessFactors.ActionNameSource TypeSource ValueData TypeCreateiflowNameExpression${camelid}java.lang.StringCreatemessageIdHeaderSAP_MessageProcessingLogIDjava.lang.StringCreateiflowStatusConstantSTART  Step 2: (Set EM control variables) – Now we used ‘Groovy Script’ to set suitable time zone with the Iflow Names. /*
This groovy script is used to set Property for EM handler
*/
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.time.ZonedDateTime;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.TimeZone;

def Message processData(Message message) {

// Retrieve integration parameters from properties
properties = message.getProperties();

// convert to HKT timezone
def timeZone = TimeZone.getTimeZone(‘HKT’);

// set today and tomorrow date to HKT timezone
def dateFormat = “yyyy-MM-dd”;

def newTodayDate = new Date();
def today = newTodayDate.format(dateFormat, timeZone);
message.setHeader(“today”, today);

//add for EM handler start
def currentTime = newTodayDate.format(“yyyy-MM-dd’T’HH:mm:ss”).toString()

//get current iflow name
String iflowName = properties.get(“iflowName”);
message.setProperty(“iflowName”, iflowName);

// set processName with time

message.setProperty(“processName”, iflowName + ” ” + currentTime);

//add for EM handler end
return message;
} Step 3: In this step we used ‘Process call’ to call the Local Integration Process (Send Event to Execution Manager).Note: To continue with the Local Integration Process (Send Event to Execution Manager) steps, kindly read from Step No. 8 to understand all the steps and working of Local Integration Process.Step 4: Here we used ‘Request Reply’ to fetch some field’s data from SuccessFactors based on the query.Query- $select=userId,city,gender,firstName,lastName&$top=50Step 5: Now we created one .xsd file and used Message Mapping to map these fields with the same fields fetched from the SuccessFactors in Previous step. All the fields are mapped using One to One mapping.Step 6: (EM END) – In this step we wrote a groovy script to set the Iflow status as ‘END’ which will be sent to the Execution Manager in SuccessFactors. /* Refer the link below to learn more about the use cases of script –
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/148851bf8192412cba1f9d2c17f4bd25.html
If you want to know more about the SCRIPT APIs, refer the link below –
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en-US/index.html */
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
message.setBody(“”);
message.setProperty(“iflowStatus”, “END”);
return message;
} Step 7: In this step we again used ‘Process Call’ to call the Local Integration Process (Send Event to Execution Manager).#Now we will configure the Local Integration Process ‘Send Event to Execution Manager’ -#Below is how the ‘Send Event to Execution Manager’ Flow looks like –Step 8: We wrote a groovy script here with the name ‘EM Event Formatter’. In this step first we get all the events in the script with message name, Id and status then made some cases based on there execution status like START, FAILED, END. import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.util.XmlSlurper;
import groovy.xml.XmlUtil;

def Message processData(Message message) {

//define the initial format and property
def text = ”’
<EMEvent>
<process>
<EMMonitoredProcess>
<processType>INTEGRATION</processType>
</EMMonitoredProcess>
</process>
</EMEvent>
”’
def EMEvent = new XmlSlurper().parseText(text)
def props = message.getProperties();

def eventNameS;
def eventDescriptionS;
def eventTypeS;
def body = “”;

String messageId = props.get(“messageId”) as String
String processName = props.get(“processName”) as String
String iflowName = props.get(“iflowName”) as String
String iflowStatus = props.get(“iflowStatus”) as String

//define the EM status
switch(iflowStatus){
case ‘START’:
eventNameS = “iflow start”
eventDescriptionS = “iflow start”
eventTypeS = “START”
break;
case ‘END’:
eventNameS = “iflow end”
eventDescriptionS = “iflow end”
eventTypeS = “END”
break;
case ‘FAILED’:
eventNameS = “iflow failed”
String exceptionMessage = props.get(“CamelExceptionCaught”) as String
eventDescriptionS = exceptionMessage
eventTypeS = “FAILED”
break;
default:
eventNameS = “”
eventDescriptionS = “”
eventTypeS = “”
}

Date currentdate = new Date();
def currentTime = currentdate.format(“yyyy-MM-dd’T’HH:mm:ss.SSS”).toString()

//define the request event, content display in process event, every message could have multiple events
EMEvent.appendNode {
eventDescription(eventDescriptionS)
eventTime(currentTime)
eventName(eventNameS)
eventType(eventTypeS)

}

//define the request process, the process should be unique for every iflow process message
EMEvent.process.EMMonitoredProcess.appendNode {
processDefinitionId(iflowName)
processDefinitionName(iflowName)
processInstanceId(messageId)
processInstanceName(processName)
}

body = XmlUtil.serialize(EMEvent).substring(38)

body = “<EMEvent>” + body + “</EMEvent>”
message.setBody(body);
return message;
} Step 9: Here we use the ‘Process Call’ with name EMHandler. It will call another IFlow we created with the name ‘ExecutionManagerProcessDirect’.Note: To continue with the Another Integration (ExecutionManagerProcessDirect) steps, kindly read from Step No. 16 to understand all the steps and working of our 2nd Integration.Step 10: We wrote groovy script here to set the body of the message as empty so that after 1st Event process completion it will continue with the rest of the process through the main flow for other events. def Message processData(Message message) {
//Body
def body =””;
message.setBody(body);
return message;
}   Step 11: Now we created an Exception Subprocess in our main Iflow which would call another Local Integration process ‘Exception Error Handling’ if any error occurred during main Integration process. Step 12: In this step we will write all the description in the body of the ‘Content Modifier’ which needs to be captured during the Interface failure.Content Modifier Body –  Please be informed that a technical issue occurred in the interface. The following information below may help to troubleshoot.

— Integration parameters —
Last run date: ${property.LSRD}

— Exception Message —
${exception.message}
— End of Exception Message —

— Stack trace —
${exception.stacktrace}
— End of Stack trace — Step 13: In this step we set the value of the IFlow status as ‘FAILED’ using below ‘groovy Script’.Groovy Script 5 – (EM Exception) – import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
message.setBody(“”);
message.setProperty(“iflowStatus”, “FAILED”);
return message;
}

/* Refer the link below to learn more about the use cases of script.
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/148851bf8192412cba1f9d2c17f4bd25.html
If you want to know more about the SCRIPT APIs, refer the link below
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en-US/index.html */ Step 14: In this step we again used the ‘Process Call’ to call the same Local Integration process ‘Send Event to Execution Manager’ so that the status of the interface can be updated as ‘FAILED’ in Execution Manger.Step 15: (EM END) – In this step we again wrote the same groovy script to set the Iflow status as ‘END’.Note: We have to set the status of an Iflow as ‘END’ after every process completion (START,FAILED) otherwise in SuccessFactors you will always see the status of the same IFlow as ‘In Progress’. It will only complete when you will use the ‘END’ Event after every process completion. import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
message.setBody(“”);
message.setProperty(“iflowStatus”, “END”);
return message;
}

/* Refer the link below to learn more about the use cases of script –
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/148851bf8192412cba1f9d2c17f4bd25.html
If you want to know more about the SCRIPT APIs, refer the link below –
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en-US/index.html */ Step 16: (Send EM Event) – In this step we again used the Process direct to call the same Local Integration process ‘Send Event to Execution Manager’ which we called in previous steps as well so that it can update the status of the interface as ‘END’ in Execution manager.#Below is our 2nd IFlow named ‘ExecutionManagerProcessDirect’ – Step 17: In this step all the data comes here through ProcessDirect from our Main IFlow. After that we wrote a groovy script to set the payload and dataStoreId as Property. import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.util.XmlSlurper;

def Message processData(Message message) {
//Body
def body = message.getBody(java.lang.String) as String;
def input = new XmlSlurper().parseText(body);

def dataStoreId = input.EMEvent.process.EMMonitoredProcess.processInstanceId.text() + ” ” + input.EMEvent.eventTime.text();

message.setProperty(“payload”,body);
message.setProperty(“dataStoreId”, dataStoreId);
return message;
} Step 18: In this step we performed the Upsert call to SuccessFactors and update all the required details in Execution Manager. To perform this action, we use ‘EMEvent’ Entity of SuccessFactors.Step 19: In this step we are using ‘Content Modifier’ in ‘Exception Subprocess’ to store all the data in case of any failure occurs during Interface execution and Interface’s status was not updated at SF due to this.Step 20: Now we stored the same data in our CPI Data stores in case we need to use the same. Monitoring in Execution Manger – Now you need to deploy both the Iflows and check the monitor the executions in execution manager at SuccessFactors. Please check below screenshots about how it looks like at SF –  Thank you for reading this Blog.   Read More Technology Blogs by Members articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author

+ There are no comments

Add yours