cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script not able to fetch values from Valu mapping table in CPI !

das_sappo
Participant
0 Kudos

Dear Experts,

I have maintained a VM table as below and trying to fetch the values accordingly through the below script. Surprisingly while simulating getting the desired output as SNDPRN (as property) but when triggering from sender then the Groovy is throwing exception as it can't find the value in VM.

Please suggest what could be issue here .

das_sappo_0-1716638749783.png

das_sappo_1-1716638847619.pngdas_sappo_2-1716638922896.png

 

 

 

 

Accepted Solutions (0)

Answers (1)

Answers (1)

Sriprasadsbhat
Active Contributor
0 Kudos

Hello,

Please check if your header is properly being set and able to see the value in Header ( using trace and not via simulation ).

Apart from that your script looks good.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import com.sap.it.api.ITApiFactory;
import com.sap.it.api.ITApi;
import com.sap.it.api.mapping.ValueMappingApi;

def Message processData(Message message) {
    //Body

    def valueMapApi         = ITApiFactory.getApi(ValueMappingApi.class, null);
    def map                 = message.getProperties();
    def sourceAgency        = map.get("sourceAgency");
    def sourceIdentifier    = map.get("sourceIdentifier");
    def sourceValue         = map.get("sourceValue");
    def targetAgency        = map.get("targetAgency");
    def targetIdentifier    = map.get("targetIdentifier");

    def value = valueMapApi.getMappedValue(sourceAgency, sourceIdentifier, sourceValue, targetAgency, targetIdentifier);

    def messageLog = messageLogFactory.getMessageLog(message);
    if (messageLog != null ) {
        if ( value != null ){
        messageLog.addAttachmentAsString("Output : Target Value Mapping is  ", value, "text/plain");
        }
        else{
            messageLog.addAttachmentAsString("Output : Target Value Mapping is  ", "Not Found", "text/plain");
        }
    }
    return message;
}

Regards,

Sriprasad Shivaram Bhat

das_sappo
Participant
0 Kudos

Thanks, Sriprasad for replying. Header value is getting stored correctly in the property IDENTIFIER and the same is showing in TRACE.

 Also, the Groovy is able to read the IDENTIFER value which can be seen in exception message as below. VM is also deployed multiple times .

das_sappo_0-1716699519526.png

das_sappo_1-1716699578270.png