Skip to Content
author's profile photo Former Member
Former Member

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

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

mm.jpg (43.8 kB)
result.jpg (32.1 kB)
Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Feb 27, 2014 at 05:26 PM

    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;

    }

    }

    Throwing Smart Exceptions in XI Graphical Mapping

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • Posted on Feb 27, 2014 at 05:03 PM

    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


    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2014 at 05:27 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • 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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.