cancel
Showing results for 
Search instead for 
Did you mean: 

How to raise a exception if the incoming value for a source field is empty

Former Member
0 Kudos

Dear all,

I have a scenario where the source and target structures are as follows :

The output for the above transformation logic is

The occurrence for field id in source and target is 1:1   Even if i don't provide the input value for id field,

system is not throwing any runtime exception.But if the field tag id is missing in incoming payload, then

system throws exception.

1) *** How can i raise a exception it the value for field id is empty

2) As the target structure occurrence for field id is 1:1  why system doesn't throw exception for null value

Regards

Koti Reddy

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

1) Simply use below UDF and throw custom exception in case ur field is empty

Input: var1

Execution type: single value

if(var1.equals(""))

{

throw new RuntimeException("Input field is empty");

}

else

{

return var1;

}

}

2) There is a difference between null (field itself is not coming in input xml) and blank value. Empty string is a valid data as a result ur mapping hasn't been failed.

Thanks

Amit Srivastava

Former Member
0 Kudos

Hello Amit,

Thanks for the input. Transformation logic is working fine. Error description in SXMB_MONI is as shown below

In the above image, it is not showing the error description "input field is empty" that was provided in UDF. As alerts were already configured for the scenario, is there any possibility to get the above  description for the error.

Regards

Koti Reddy

Former Member
0 Kudos

Hello,

The UDF code which i have provided above will only help u in throwing custom exception in mapping but if u want to reflect custom message under moni also then u have to implement the steps which are explained in above blog.

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Amit,

Along with the mapping validation on field id, i have to include the name of the employee in exception as "Input field is empty for : NAME"

so that the user can easily identify that Input value is empty for field id while processing the record for so and so NAME.

How to meet this requirement in UDF.

Regards

Koti Reddy

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

If you want to raise a custom exception in mapping use the below udf.

Ex:id -->mapwithdefault-->udf-->id

if(!id.equals("")){return id;}

else{throw new StreamTransformationException("Source field \"id\" value is empty");}

As above said in your example it didn't throw default error because you are passing empty value(tag without any value).

It will throw error when you pass null value i.e (without tag )

Regards

Venkat

Former Member
0 Kudos

Hi venkat,

can you please help me on my task same as like this,

when the field is empty then PI mapping is fail and throw the error like "field parameter is missing,please check the table entries ".

my field is 0 to 1(string),please give me graphical mapping not UDF.

Thanks

kumar

vadimklimov
Active Contributor
0 Kudos

Hello Kumar,

As described by other members earlier, make use of standard function mapWithDefault ("") followed by UDF throwing StreamTransformationException in case the value is empty. I don't think you can fulfil such requirement with the customized error message with pure standard graphical mapping functions, without UDF.

May I also wonder why usage of UDF is not an option for you?

Regards,

Vadim

former_member184720
Active Contributor
0 Kudos

1) *** How can i raise a exception it the value for field id is empty

You need to impliment the check  to throw the error

2) As the target structure occurrence for field id is 1:1  why system doesn't throw exception for null value

You are sending a blank value " " and the same is being passed. if you remove the tag from source xml it'll throw the error

Message was edited by: Hareesh Gampa