cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CPI Message Mapping Issue: Handling Empty & Null CountryCode with Conditional Mapping

NS502079
Explorer
418

Hi,

I am facing an issue with SAP CPI Message Mapping, where I need to control the creation of a Address field based on the CountryCode. The problem arises when CountryCode is null or empty, causing the mapping to fail.

I have tried various Mapping approaches, including ifWithoutElse(), equals(), exists(), and not(), but I still cannot get the desired output in all cases. I am reaching out to see if anyone has encountered a similar issue or can suggest a working solution.

Expected/Actual Behavior

Expected Behavior

CountryCode (Input)Processed CountryCodeOutput

"NO""NO"false
"SE""SE"true
"" (empty)"Empty"true
null"Empty"true
"US""US"true

This means:

  • The output should always be true unless CountryCode = "NO", in which case it should return false.
  • If CountryCode is null or "" (empty), it might be converted to "Empty" in order to be processed (not sure if this is the most effective approach) but still always return true.

Actual Behavior

  • When CountryCode is null, the mapping either returns null or does not process correctly.
  • The or() function sometimes receives null instead of true/false, causing failures.
  • Using ifWithoutElse() for CountryCode does not always ensure a valid output.
  • equals(CountryCode, "NO") returns null instead of false when CountryCode is missing.

Current Mapping Approach (Not Working)

I have tried the following Message Mapping functions:

  1. Ensure CountryCode is never null before checking "NO"

    • Using ifWithoutElse(Not(Exists(ns0:CountryCode)), "Empty")
  2. Check if CountryCode is "NO"

    • Using equals(ifWithoutElse(), "NO")
  3. Check if CountryCode is "Empty"

    • Using equals(ifWithoutElse(), "Empty")
  4. Use or() to check if CountryCode is "NO" or "Empty"

    • or(equals("NO"), equals("Empty"))
  5. Use Not(or()) to determine if Address should be created

    • Not(or()) → And() → CreateIf()

Issue

  • equals(ifWithoutElse(), "NO") sometimes returns null instead of false.
  • The or() function does not handle null values properly, causing an empty result.
  • Not(or()) is not always returning the expected true/false values.

Alternative Approaches Tried

1. Groovy Script Attempt (Did Not Work)

We attempted a Groovy script to handle null, "NO", and empty values, but encountered:

  • MissingPropertyException when CountryCode is null.
  • The script still produced null outputs instead of true/false.

2. Using fixContexts(), collapseContexts(), and removeContexts()

  • These functions did not ensure CountryCode was always valid before processing.

3. Using mapWithDefault() or copyValue()

  • These functions did not resolve null values correctly before checking "NO".

Questions

  1. How can I correctly ensure that CountryCode is always processed as a valid string (never null) before checking "NO"? (if this is necessary)
  2. Is there a better way to handle the logic in Message Mapping without requiring Groovy?

I have attached a picture of what i have. The input "CountryCode" as well as the "and" function that "CountryCode" has to be connected to with either the value "true" or "false" depending on the rules stated earlier in this post.

Thanks in advance!

Accepted Solutions (1)

Accepted Solutions (1)

ag3silaus
Participant

Hi @NS502079 ,

I hope that works for you, I tested with CountryCode and without. You can also try it.

ag3silaus_0-1739264470410.png

 

Have a nice day 

Burak

NS502079
Explorer
0 Kudos
Thanks for the input. I tried with "mapWithDefault" right after country code and that seems to have fixed the issue. However, now to issue is the output after "createIf" if you see the attached picture in the OP. The "and" function produces a true value to the "createIf" function but the output from there on is null. This results in the Address field not being created. Do you have any input here?
ag3silaus
Participant
0 Kudos
Hi again, i created to mapping regarding your needs. You can take the part what do you need. If you provide me to sample XML and XSD's i can clarify more spesific. But If you create mapping same as mine it will be return what your expected behavior.

Answers (0)