cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly omit an element in target message structure

0 Kudos

Hi,

I'm having a problem removing the target element in a mapping depending on a condition in PI 7.1.

The requirement is for the message mapping to create or omit a target element depending on the content of the input field.

Specifically, if the input field is populated, then I need to populate the target field with the input value.

If the input field contains spaces, then I need to omit the target field completely.

My target element is optional (cardinallity 0..1).

I did the following

So, I only want to create the target element if the substring(0..10) is not all spaces.

This works when the input field contains a value.  However, when it doesn't I get the familiar error: values missing in queue.

I understand why the error would appear if the target field was mandatory.  But in my case it's optional.  Am I missing something?

By accident, I found that if I replace trim with a UDF that does the same thing (string.trim()), and use (All values of queue), then it actually works -  - the target field is successfully omitted if the input field is all spaces.  This indicates that it has something to do with context changes but I don't undertand the exact reason.

Does anybody know why this works when using (All values of queue)?  Is this the proper way of doing this activity?

Many thanks!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

In your IF..THEN... use properties "Keep Suppress", to keep the surppressed lines, and have the same context entries. Else, lines inside a context will be less than expected and your data will be inside the  wrong target context.

regards.

Mickael

0 Kudos

Hi Mickael,

Thanks for your answer.  I don't know that much about this option and haven't found a lot of documentation.    I wan't to remove the element when receiving all spacess in the input - not keep it.  The element that I want to remove is not a node - it doesn't have any children elements. 

I tried the option anyway and it didn't fix my problem.  Are you suggesting ticking it anyway in order to ensure the correct distribution of data in the output xml irrespectively of the problem?

Thanks again!

Answers (3)

Answers (3)

rcsegovia
Active Participant
0 Kudos

I think you should try with createIf fuction:

markangelo_dihiansan
Active Contributor
0 Kudos

Hello Georgia,

Using variables in graphical message mapping can sometimes work or not work. It is best used when passing single values only, when passing contexts or whole queues the behavior cannot be predicted.

Also, can you try using ifS instead of the if function? Are you using that logic in a mandatory field mapping?

Hope this helps,

Mark

0 Kudos

Hi Mark,

The variable just contains a single string element.. not a whole structure.  Hence, the input field is a single field.

The target field is an optional field (cardinallity 0..1) with no subelements.  It's not a node.

Using the UDF with queue processing type to do a string.trim()  instead of the trim node function works. (I do the operation only on the first element [0] of the argument list in the UDF)  But because I don't fully understand why it works, I'm a bit reluctant to use it.  The input field is a single element and the output field is a single element.  Hence why I don't understand why the context makes such a big difference.

However, the point is that I still need to remove the element from my result xml.  It's an optional element and should be completely ommited unless it contains a valid value according to the validation requirements of the recipient system.  it sounds like something that shouldn't be too complicated to do.  Is there a recommended way of doing this?  Any thoughts?

Point taken about the ifS. 

Many thanks,

Former Member
0 Kudos

Hello,

Ur mapping looks OK to me... Are u sure the value missing error is coming for this field only?

Thanks

Amit Srivastava

Edited: Mapping screenshot

markangelo_dihiansan
Active Contributor
0 Kudos

Hello Georgia,

If that is the case, you can use the constant function called copyValue[0] to only get the first input of that field. Usually, the values missing in queue error occurs when you are passing a null/suppress value into a field that is supposed to occur at least once (1..1 or 1..unbdounded).

There is a sap note the explains the difference between if and ifs. I think in if, it evaluates both the inputs for if and then before passing the output whereas in ifs, it evaluates the input for if only and when it is satisfied, the condition for the then is evaluated.

Regards,

Mark

Former Member
0 Kudos

Hi Georgia,

You can probably use 'mapWithDefault' before the 'trim' function to default the field to an empty string.

Regards,

Koen

0 Kudos

Hi Koen,

The recepient system that will process my output xml does not accept emtpy strings - it fails when it does validation.  If the field does not contain a date, I need to remove the field completely. 

I.e. I wan't to remove the 'datefield' below.

In

<field1>blabla</filed1>

<datefield>                      </datefield>

<field2>blabla2</field2>

Out

<field1>blabla</field1>

<field2>blabla2</field2>

It's something that I can do very easily in xsl but is proving a bit harder in PI even though the datefield is an optional field - i'm sure I'm missing something basic!.  (I would rather not use xsl in pi for many reasons unless absolutely necessary.) 

Any further thoughts appreciated!

Many thanks,