cancel
Showing results for 
Search instead for 
Did you mean: 

CPI- accessing value mapping using groovy script

anitabarge
Discoverer
0 Kudos
16,252

Hello Everyone ,

I want to access the value mapping in my Integration Flow.

Currently , In my graphical mapping, I have tried accessing value mapping using the standard Value Mapping function . But I want to access the value mapping using groovy script - no graphical mapping used. Whole mapping is written in groovy script only . But I am not able to access the value mapping in this scenario. Can you please help me out here?

Accepted Solutions (1)

Accepted Solutions (1)

MortenWittrock
Active Contributor

Hi Anita

Yes, it's possible to access value mappings from a Groovy script. Here's how to do it:

def valueMapApi = ITApiFactory.getApi(ValueMappingApi.class, null)
def value = valueMapApi.getMappedValue('source-agency', 'source-identifier', 'source-value', 'target-agency', 'target-identifier')

In order for this to work, include the following two import statements in your script:

import com.sap.it.api.ITApiFactory
import com.sap.it.api.mapping.ValueMappingApi

Javadoc documentation here: ITApiFactory ValueMappingApi

Regards,

Morten

mhitelli
Explorer
0 Kudos

Hello Morten,

Thanks for the answer! Is it also possible to use the value mapping out on a XSLT mapping?

Best Regards,

Maximilian

PiotrRadzki
Active Participant

Thanks Morten, works great.

Answers (1)

Answers (1)

0 Kudos

How to pass a dynamic value for source-value?
def value= valueMapApi.getMappedValue('source-agency','source-identifier','source-value','target-agency','target-identifier').

I have tried the following code but it gives error as follows "Cannot retrive artifact for empty alias@"

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

def Message processData(Message message) { // get the message Properties def mProp = message.getProperties(); String site = mProp.get("Local_Prop_site"); // read the value mapping to get the security credential def valueMapApi = ITApiFactory.getApi(ValueMappingApi.class, null) String secretCredID = valueMapApi.getMappedValue('SRC', 'Site', site , 'DEST', 'Credential');

Thanks,

Thosif Chand.