cancel
Showing results for 
Search instead for 
Did you mean: 

In an iflow in CPI How can I replace content of a .CSV file that I am taking from an sftp?

juanforero5
Participant
0 Kudos

Hello everyone, I need your help. I am taking from the client's SFTP a file with a .CSV extension which brings the following content

EMPLOYEE_ID,DAYS_OFF,WORK_DT,INDICATOR,BATCH_ID
"1047,""1"",""2023-01-22"",""I"",""2363281998"""
"1139,""1"",""2022-11-27"",""I"",""2363281998"""
"1139,""1"",""2023-01-15"",""I"",""2363281998"""
"1139,""1"",""2023-01-29"",""I"",""2363281998"""
"1139,""1"",""2023-02-19"",""I"",""2363281998"""
"1223,""1"",""2023-02-26"",""I"",""2363281998"""
"1428,""1"",""2023-02-19"",""I"",""2363281998"""

I need to somehow remove all the double quotes (") that are in the file. That is, it looks like this.

EMPLOYEE_ID,DAYS_OFF,WORK_DT,INDICATOR,BACTH_ID
1047,1,2023-01-22,I,2363281998
1139,1,2022-11-27,I,2363281998
1139,1,2023-01-15,I,2363281998
1139,1,2023-01-29,I,2363281998
1139,1,2023-02-19,I,2363281998
1223,1,2023-02-26,I,2363281998
1428,1,2023-02-19,I,2363281998

Could you help me with a groovy script or some function that allows me to modify the payload in this way? since in the next step there is a CSV to XML converter and if the payload arrives with the double quotes (") it generates an error

MortenWittrock
Active Contributor

Hi Juan

If you haven't tried writing a script for this yet, you really should. You need to understand any code you add to your solution, so sooner or later you'll have to tackle some Groovy (or JavaScript) code.

Regards,

Morten

Accepted Solutions (1)

Accepted Solutions (1)

karthikarjun
Active Contributor

Hi jdforero - Would you add the below JavaScript to replace all the double quotes from the message body?

importClass(com.sap.gateway.ip.core.customdev.util.Message);
importClass(java.util.HashMap);

function processData(message) {
    //Get and Set the Body 
    var getBody = String(message.getBody( new java.lang.String().getClass()));
    var replaceDoubleQuots = getBody.replace(/"/g, "");
    message.setBody(str)

    return message;
}

Answers (0)