Integration

Get Involved. Join the Conversation.

Topic

    Pooja I
    Conditional Mapping in OICAnswered
    Topic posted July 26, 2019 by Pooja IBronze Medal: 1,250+ Points, tagged Cloud, Integration, Mapping, Orchestration, xml 
    147 Views, 16 Comments
    Title:
    Conditional Mapping in OIC
    Summary:
    Issue in conditional Map
    Content:
    Hi Team,
          Below is the input XML structure which i am trying to have conditional mapping.
    <Phone_Hierarchy>
       <Phone_Details>
          <Phone_Info>
             <Phone_Primary_ID>test</Phone_Primary_ID>
             <Phone_ID>test</Phone_ID>
             <Phone_Number>978-5567</Phone_Number>
           </Phone_Info>
        </Phone_Details>
        <Phone_Details>
           <Phone_Info>
              <Phone_Primary_ID>test</Phone_Primary_ID>
              <Phone_ID>test1</Phone_ID>
              <Phone_Number>9728524522</Phone_Number>
           </Phone_Info>
         </Phone_Details>
    </Phone_Hierarchy>
     

    The CONDITION CHECK IS: 

      if Phone_Primary_ID == Phone_ID then map Phone_Number else empty element.
      
      below is the looping which i tried
      
      for each of Phone_Details
           if ( Phone_Primary_ID == Phone_ID )
          then 
                map Phone_Number
          else
                ""
       
       This was printing concatinated result of all the Phone_Number like 978-55679728524522
       
     
      
       Alternatively, what i thought of is,
       
       for each of Phone_Details   //loop through all the phone_details
        if(boolean = true)         //exit loop when the condition becomes false
            if ( Phone_Primary_ID == Phone_ID )
             then 
                map Phone_Number
                set boolean =false;    //here i am not able to reassign boolean and the xpath is throwing errors.
      else
       ""
       
       I know that this is specific case, since this is totally new to me, I need some insight on this
    Image:

    Best Comment

    Hemanth Lakkaraju

    Where did you see the error - Designtime on UI or Runtime? If runtime, are you sure the expressions in concat doesn't return multiple values?

    Comment

     

    • Hemanth Lakkaraju

      Can you share few more information on the request xml and required format? Is Primary_Phone element to which you are mapping is a repeating element or within a repeating element?

      The logic in option#1 is almost correct unless the condition/value-of is picking complete xpath expression instead of current for-each position. Did you check the expression? If Primary_Phone element is non-repeating and you still want to have condition such way, the for-each loop iterates over all occurrences of Phone_Details and repeating values are expected for all cases the condition is matching.

      • Pooja I

        Hi Hemanth,

              The request XML is output of HCM Extract. The output format is CSV. So i am transforming XML to CSV here. 

        Primary_Phone is within "Phone_Details" repeating element. 

         

        Yes Primary_Phone is Not repeating element, so the output should have only which have matched cases.

        I've added the for-each here because 

        a person can have n-number of phones

        so I need to loop through all the phones of a person and identify where Phone_Primary_ID == Phone_ID.

         

        • Hemanth Lakkaraju

          Yes Primary_Phone is Not repeating element, so the output should have only which have matched cases. I've added the for-each here because a person can have n-number of phones 

          In this case, the output is expected to see concatenated value for all matching conditions.

          Primary_Phone is within "Phone_Details" repeating element. 

          Based on my understanding, In this case, the for-each (Phone_Hierarchy/Phone_Details) should be on target Phone_Details (which is repeating element). And then within the Primary_Phone, add an xsl:if with the condition Phone_Info/Phone_Primary_Id=Phone_Info/Phone_Id and then within the if, use xsl:value-of with Phone_Info/Phone_Number.

    • Pooja I

      Meanwhile,

         Is there any way to Validate the Mapping, I tried test feature of mapping, but it gives only partial output. Also the feature at Actions -> Show Context, hadn't gave the right expressions.

      • Hemanth Lakkaraju

        Not sure I understand what you meant by this

        but it gives only partial output. Also the feature at Actions -> Show Context, hadn't gave the right expressions

        What's your expectation. There is a Validate button already!

        Is there any way to Validate the Mapping 

        • Pooja I

          Is there any way to Validate the Mapping  -  " CHECK WHETHER THE CONDITIONAL MAPPING IS ALIGNED TO XPATH STANDARDS"

           
          by PARTIAL OUTPUT, what i meant was, 
          When we do "TEST" in map page, I didnt find the complete response. attached a screenshot.
          • Hemanth Lakkaraju

            The screenshot looks fine per my understanding. The response will only be shown based on your mappings.

            The validate functionality do check the xpaths accuracy. I'm still not clear what is your expectation here.

            • Hemanth Lakkaraju

              From the screenshot the expression you need for Primary_Phone is:: 

              /Phone_Hierarchy/Phone_Details[Phone_Info/Phone_Primary_ID=Phone_Info/Phone_ID]/Phone_Number

              No need of any xsl constructs except the predicates in the single xpath.

    • Pooja I

      Hi Hemanth,

             I have a doubt here. Do conditional Mapping work fine with xpath functions?

      I tried an conditional IF, it worked fine for direct mapping but it threw invalid Xpath Expression error when i used Concat function.

      I have attached both the mapping screenshots. Please provide your valuable insights :)

      • Hemanth Lakkaraju

        Where did you see the error - Designtime on UI or Runtime? If runtime, are you sure the expressions in concat doesn't return multiple values?

        • Pooja I

          The error is in runtime. yes, i am sure concat didn't produce the results. The integration failed stating, "xpath expression is invalid"

          • Hemanth Lakkaraju

            For your flow design

                        1. After DownloadToICS, use StageWrite with opaque schema with a different fileName and directory location.
                        2. Within the mapping to stageWrite request do something similar to this:
                           
                           <opaqueElement> 
                           <xsl:value-of select="oraext:encodeBase64(
                           concat(
                           substring-before(oraext:decodeBase64(oraext:encodeReferenceToBase64($downloadFileResponse/fileReference)),'DATA_DS'),
                           'DATA_DS xmlns="http://xmlns.oracle.com/cloud/adapter/nxsd/surrogate/ReadFile"',
                           substring-after(oraext:decodeBase64(oraext:encodeReferenceToBase64($downloadFileResponse/fileReference)),'DATA_DS')
                           ))"
                           </opaqueElement>
                        3. Update the Stage Read chunking with the fileName and directory as mentioned in Stage Write in Step#1.
                        4. Below is the mapping logic you need to place within the Primary_Phone
                                           <nsmpr5:Primary_Phone xml:id="id_213">
                           <xsl:for-each select="smpr2:Phone_Hierarchy/nsmpr2:Phone_Details/nsmpr2:Phone_Info">
                                 <xsl:if test="nsmpr2:Phone_Primary_ID=nsmpr2:Phone_ID" xml:id="id_214">
                                    <xsl:choose xml:id="id_215">
                                       <xsl:when test="'string-length(nsmpr2:Phone_Area_Code)>0'" xml:id="id_216">
                                          <xsl:value-of select="concat('(',nsmpr2:Phone_Area_Code, ')',nsmpr2:Phone_Number)" xml:id="id_217"/>
                                       </xsl:when>
                                        <xsl:otherwise>
                                        <xsl:value-of select="concat('()',nsmpr2:Phone_Number)" xml:id="id_217"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                 </xsl:if>
                               </xsl:for-each>
                           </nsmpr5:Primary_Phone>
                        5. This should solve the problem. If it doesn't work, please share the update IAR.

            • Pooja I

              Sure Hemanth. I will check and get back to you!

            • Pooja I

              Hi Hemanth,

                  I implemented the Solution you gave, still same issue. I have attached the IAR to the SR. Please review and let me know the changes..

              • Hemanth Lakkaraju

                The namespace for response got changed because it seems you used a new stage read with different name. In the Write Stage request mapping replace

                 'DATA_DS xmlns="http://xmlns.oracle.com/cloud/adapter/nxsd/surrogate/ReadFile"'

                with

                 'DATA_DS xmlns="http://xmlns.oracle.com/cloud/adapter/nxsd/surrogate/ReadInSeg"',

                and try! Also your mapping for csv creation is incorrect - you are not iterating for-each over assignment_details and hence the response might look very weird. 

                • Pooja I

                  Hi Hemanth,

                     The output file is getting mapped with input data. But the coniditons which included concat are being displayed as such. Missed to loop in the assingment details. i have updated the IAR file in SR. Please review and provide your feedback :)