cancel
Showing results for 
Search instead for 
Did you mean: 

CPI Handling Null Values With Multiplication Mapping Function

0 Kudos

I have a requirement to multiply one value by 0.9 in message mapping, however the value (from hash map) to be multiplied is not always present. If the value to be multiplied is null, then a mapping error "cannot cast "" to decimal value occurs". I've found that replacing the null value with a 0 solves the problem, but I again have to replace the 0 with spaces after the multiplication step since the field should not contain a 0 value. It seems that true/false values of if statements are evaluated regardless of the condition, and so I've not been able to use this method.

I believe maybe there is a better way to handle this, but I have not found it. I welcome any suggestions. I am basically looking for a straightforward way to do "y" action if "x" value is not null Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

bhalchandraswcg
Contributor
0 Kudos

Hi mawalker,

The standard function multiply handles both the cases. When the input has value it multiplies with 0.9. When the input is null, the output is null.

If you need spaces instead of null, you can add mapWithDefault function after multiplication.

The above will work where input is either null or has a number value. When the input has blank value, that's when you get cannot cast "" error. The best way to resolve this would be to solve it in the sender system. If the field is of type decimal/double, a blank is not a valid value.

Hope this helps,

Bala

0 Kudos

Hi Bhalchandra,

Thanks very much for your helpful response. It turns out that the input value was spaces and not null, which was causing me the issue as you pointed out. I've been able to use the fix values function to replace the space with a zero so the multiplication function will not error. I've then replaced the zero back with a space at the end of this mapping step. Thanks again for your help.

Regards,

Matthew

Answers (0)