Search code examples
informaticainformatica-cloud

Supporting optional parameters in an Informatica Integration Assignment Step


My current implementation request body does not support optional attributes:

enter image description here

If say phoneHome is null, then the wanted behaviour is for the JSON to not include the attribute at all, e.g. what I want is :

{ 
    "phoneWork": "value here",
    "phoneMobile": "value here",
    "email": "value here"
}

Not:

{ 
    "phoneHome": "",
    "phoneWork": "value here",
    "phoneMobile": "value here",
    "email": "value here"
}

I have tried looping through all elements in the event and returning only the values that are not null, but I am not able to get it working. Pseudocode:

for $i in
(
    $input.event_input[1]/xxx_Contact_Work_PHONE__c,
    $input.event_input[1]/xxx_Contact_Home_PHONE__c,
    $input.event_input[1]/xxx_Contact_Mobile_PHONE__c,
    $input.event_input[1]/xxx_Contact_Contact_EMAIL1__c 
)
return if ($i = "null")
then do nothing
else add the attribute to a JSON

Is there a way to do this?


Solution

  • The following formula, when given an XML as input, will remove all elements with no data.

    Example

    With the following input

    <note>
      <to>Tove</to>
      <from></from>
      <heading>Reminder</heading>
      <body>Don't forget me this weekend!</body>
      <element></element>
    </note>
    

    it produces the following output

    <note>
      <to>Tove</to>
      <heading>Reminder</heading>
      <body>Don't forget me this weekend!</body>
    </note>
    

    This is the solution I found:

    <!--Initialize variable with the input XML-->
    let $sources:=$input.XML_input
    <!--Initialize variable with the distinct nodes using X-PATH-->
    let $labels:=fn:distinct-values($sources/*/fn:node-name(.))
    return
    for $s in $sources
        return 
        <source>
        {
        for $l in $labels
            <!--Return element if value exists, nothing if no value-->
            return 
            if (fn:exists($s/*[fn:node-name()=$l]/text()))
            then ($s/*[fn:node-name()=$l])
            else ""
        }
        </source>