Focal Point
Passing null to custom function from within a Transform

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/1381057331/m/8067065795

January 25, 2011, 09:28 AM
RobT
Passing null to custom function from within a Transform
Hello,

I am calling a custom function from within an XML to XML Transform. The function accepts several parameters which are populated from the transform input document.

Whenever I try to pass a null value as one of the parameters using either @NULL or by mapping an empty element (eg ) then it seems the function actually receives an empty string and not a null.

Does anyone have a solution for this?


(iWay 6.0.1 on Intel/Linux)


iWay 6.0.1 on Intel/Linux
January 26, 2011, 07:19 AM
AdeH
Hi Rob,
You need to use the code tags if you're putting xml / html into your post.

Cheers,
Ade


iWay 5.5 SMSP1 and 6.0.1 on Intel/Linux
January 26, 2011, 10:44 AM
iWay Newbie
Hi,

You can try to enable the debug traces and see what is actually being retreived from your document and what is being sent to your custom function.

How does the custom function reporting that it is receiving an empty string?

quote:
Originally posted by RobT:
Hello,

I am calling a custom function from within an XML to XML Transform. The function accepts several parameters which are populated from the transform input document.

Whenever I try to pass a null value as one of the parameters using either @NULL or by mapping an empty element (eg ) then it seems the function actually receives an empty string and not a null.

Does anyone have a solution for this?


(iWay 6.0.1 on Intel/Linux)



--
WebFOCUS 8.2.03 on Linux
January 27, 2011, 05:22 AM
RobT
Thanks for your responses so far.

The empty XML element I was trying to display in my original post was
<movementSubType/>


A section of the debug logs are shown here.

09:59:54.647 DEBUG W.O_STATUS_CON_MQ.7 TranslateMovementCode : returning from execute method , took time : 1
09:59:54.647 DEBUG W.O_STATUS_CON_MQ.7 movementSubType is EMPTY String :::
09:59:54.646 DEBUG W.O_STATUS_CON_MQ.7 movementSubType is :::
09:59:54.646 DEBUG W.O_STATUS_CON_MQ.7 movementType is ::: RO
09:59:54.646 DEBUG W.O_STATUS_CON_MQ.7 Argument length is ::: 2
09:59:54.646 DEBUG W.O_STATUS_CON_MQ.7 TranslateMovementCode : inside execute method


As you can see, our custom function's logging tells us it received an Empty String (this logging was specifically added to the function to troubleshoot this particular problem). Also, the final results returned by the function indicate it received an empty string and not a null.


iWay 6.0.1 on Intel/Linux
January 27, 2011, 10:02 AM
<nklamen>
The pre-defined @NULL function represents the empty constant parameter, and it is not applicable for the use cases that you described. But if you’d like to pass NULL parameter into Transformer custom function call, it needs to be represented by a null context (context is Transform input document path, similar to XPATH) which would be the context that does not exist in the input. Here is an example on how to define the null context parameter to be passed into your custom function. It can be any unique context that is not expected in the data. It is recommended to be used as global constant. You can define it in your custom function and pass it as constant mapping, for example:

(1) In the function code:
static final String NULL_CONTEXT = “NULL/NULL”;
(2) In the transform project:
Define null context as global variable, or global constant.
- Open transform properties and create a new global constant with name NULL_CONTEXT and map it to a constant with a value same as one defined in the function: NULL/NULL
When designing mappings between input and output structures, use NULL_CONTEXT instead of @NULL function.
@CUSTOM_FUNC (‘abc’, @GETCONSTANT(‘NULL_CONTEXT’))
January 27, 2011, 10:09 AM
iWay Newbie
Hi again,

I might be off here because you mentionned trying to pass @NULL before, but you know that there is no "NULL" in XML since everything is a string... So, I understand there are 2 ways of creating a NULL value. For example:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <FirstNULL xsi:nil="true">
</root>


/root/FirstNULL 
if it is defined with the nillable attribute set to true.
/root/SecondNULL
if the element is defined but not showing.

The other thing you could try is to modify your code to handle NULL or emptry strings as null values...

quote:
Originally posted by RobT:
Thanks for your responses so far.

The empty XML element I was trying to display in my original post was
<movementSubType/>


A section of the debug logs are shown here.

09:59:54.647 DEBUG W.O_STATUS_CON_MQ.7 TranslateMovementCode : returning from execute method , took time : 1
09:59:54.647 DEBUG W.O_STATUS_CON_MQ.7 movementSubType is EMPTY String :::
09:59:54.646 DEBUG W.O_STATUS_CON_MQ.7 movementSubType is :::
09:59:54.646 DEBUG W.O_STATUS_CON_MQ.7 movementType is ::: RO
09:59:54.646 DEBUG W.O_STATUS_CON_MQ.7 Argument length is ::: 2
09:59:54.646 DEBUG W.O_STATUS_CON_MQ.7 TranslateMovementCode : inside execute method


As you can see, our custom function's logging tells us it received an Empty String (this logging was specifically added to the function to troubleshoot this particular problem). Also, the final results returned by the function indicate it received an empty string and not a null.



--
WebFOCUS 8.2.03 on Linux