Wednesday 29 September 2021

SAP CPI Helper -Chrome Plugin for SAP CPI/HCI

We have a better feature in SAP CPI to enable the trace using the chrome plugin instead of changing the log level in the manage integration content.


To enable the chrome plugin "SAP CPI Helper":

1.Chrome browser -> Settings -> Extension -> Left top corner click three lines near to Extensions.

2. Below can see Open Chrome webstore -> Serach for "SAP CPI Helper"

3. Install it and can reopen the browser

4. Logout and login to the CPI tenant -> Go to Iflow developer page.

5. Can see the new option at right top corner as "Trace, Message, Info"

6. Here you can enable trace and when you change and deploy, the trace will be automatically activated.


This is a useful feature for the developer. Hope this helps, please do comment.




Friday 3 September 2021

Remove/replace xml tags and xml nodes from the error response to make valid json format in SAP CPI


Remove the xml tags and send only the error text to the target system from the exception process/negative response.

Groovy Script:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.lang.*
def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String;
body = body.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim(); //Replace xml node
body = body.replaceAll("<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">","").trim();
body = body.replaceAll("<code>ERROR</code>", "").trim();
body = body.replaceAll("</message>", "").trim();
body = body.replaceAll("<message xml:lang=\"sv\">", "").trim();
body = body.replaceAll("<error>", "").trim();
body = body.replaceAll("</error>", "").trim();
body = body.replaceAll("\\\t|\\\n|\\\r","");
message.setBody(body);
return message;
}

Input:

{
"Response":
    {
    "status": "Error",
    "statusCode": "500",
    "C4CObjectID": "",
    "error": "<?xml version="1.0" encoding="utf-8"?><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><code>ERROR</code><message xml:lang="sv">Invalid syntax in email address</message></error>"
}
}

Output:

{​​​​​​​​
"Response":
{​​​​​​​​
"status": "Error",
"statusCode": "500",
"C4CObjectID": "",
"error": " Invalid syntax in email address" }​​​​​​​​}​​​​​​​​