5 Replies Latest reply on Apr 1, 2014 2:45 AM by RAMMII

    For-loop with counter variable in xquery in OSB

    RAMMII

      I have below xml. I have to compare PRIMARYID field value in each node and if it is same, ClaimID field should be updated with same value else it should not get updated. Can anyone tell me how to do this in OSB. Thanks.

       

      <InputParameters>

      <choice>

          <ClaimID>12</ClaimID>

          <FACILITYID>123456</FACILITYID> 

          <PRIMARYID>1234</PRIMARYID>

        </choice>

        <choice>

          <ClaimID>13</ClaimID>

          <FACILITYID>123456</FACILITYID>

          <PRIMARYID>1234</PRIMARYID>

        </choice>

        <choice>

          <ClaimID>14</ClaimID>

          <FACILITYID>123456</FACILITYID>

          <PRIMARYID>2345</PRIMARYID>  

        </choice>

        <choice>

          <ClaimID>15</ClaimID>

          <FACILITYID>123456</FACILITYID>   

          <PRIMARYID>2345</PRIMARYID>   

        </choice>

      </InputParameters>

        • 1. Re: For-loop with counter variable in xquery in OSB
          user11274260

          are you saying if duplicate primaryid is present then its corresponding clamid has to be replaced with primaryid in all occurances.

          • 2. Re: For-loop with counter variable in xquery in OSB
            RAMMII

            Thanks for the reply,

             

            My requirement is if same primaryid present then its corresponding claimid has to be replaced by the first occurance of claim ID which has same primaryid.

             

            Example:

             

            If my input is:

             

            <InputParameters>

            <choice>

                <ClaimID>12</ClaimID>

                <FACILITYID>123456</FACILITYID>

                <PRIMARYID>1234</PRIMARYID>

              </choice>

              <choice>

                <ClaimID>13</ClaimID>

                <FACILITYID>123456</FACILITYID>

                <PRIMARYID>1234</PRIMARYID>

              </choice>

              <choice>

                <ClaimID>14</ClaimID>

                <FACILITYID>123456</FACILITYID>

                <PRIMARYID>2345</PRIMARYID> 

              </choice>

              <choice>

                <ClaimID>15</ClaimID>

                <FACILITYID>123456</FACILITYID>  

                <PRIMARYID>2345</PRIMARYID>  

              </choice>

            </InputParameters>

             

            Output required is:

             

            <InputParameters>

            <choice>

                <ClaimID>12</ClaimID>

                <FACILITYID>123456</FACILITYID>

                <PRIMARYID>1234</PRIMARYID>

              </choice>

              <choice>

                <ClaimID>12</ClaimID>

                <FACILITYID>123456</FACILITYID>

                <PRIMARYID>1234</PRIMARYID>

              </choice>

              <choice>

                <ClaimID>14</ClaimID>

                <FACILITYID>123456</FACILITYID>

                <PRIMARYID>2345</PRIMARYID> 

              </choice>

              <choice>

                <ClaimID>14</ClaimID>

                <FACILITYID>123456</FACILITYID>  

                <PRIMARYID>2345</PRIMARYID>  

              </choice>

            </InputParameters>

             

            Please let me know how can i achieve this...

            • 3. Re: For-loop with counter variable in xquery in OSB
              Josh-Oracle

              Something like this may work:

               

              let $input :=

              <InputParameters>

                <choice>

                  <ClaimID>12</ClaimID>

                  <FACILITYID>123456</FACILITYID>

                  <PRIMARYID>1234</PRIMARYID>

                </choice>

                <choice>

                  <ClaimID>13</ClaimID>

                  <FACILITYID>123456</FACILITYID>

                  <PRIMARYID>1234</PRIMARYID>

                </choice>

                <choice>

                  <ClaimID>14</ClaimID>

                  <FACILITYID>123456</FACILITYID>

                  <PRIMARYID>2345</PRIMARYID> 

                </choice>

                <choice>

                  <ClaimID>15</ClaimID>

                  <FACILITYID>123456</FACILITYID>  

                  <PRIMARYID>2345</PRIMARYID>  

                </choice>

              </InputParameters>

              return

                <InputParameters>{

                  for $choice in $input/choice

                  let $withSamePrimaryID := $input/choice[PRIMARYID eq $choice/PRIMARYID]

                  let $claimID := $withSamePrimaryID[1]/ClaimID

                  return

                    <choice>{$claimID}{$choice/FACILITYID}{$choice/PRIMARYID}</choice>

                }</InputParameters>

              • 4. Re: For-loop with counter variable in xquery in OSB
                RAMMII

                Thanks a lot.. It worked fine. There are few more tags in the xml, i need to compare like FIRSTNAME along with PRIMARYID before updating ClaimID. I am using below code but it is not working. Could you please help.

                 

                  {

                                for $choice in $inputParameters1/choice

                                return

                                    <choice>              

                                {

                                if(($inputParameters1/choice[PRIMARYID eq $choice/PRIMARYID ]) and ($inputParameters1/choice[FIRSTNAME eq $choice/FIRSTNAME ])) then

                                 let $withSamePrimaryID := ($inputParameters1/choice[PRIMARYID eq $choice/PRIMARYID ])

                                 let $claimID := $withSamePrimaryID[1]/ClaimID

                                 return

                                 <ClaimID>{$claimID}</ClaimID> 

                                 else

                                 <ClaimID>{ data($choice/ClaimID) }</ClaimID> 

                                 }                                    

                                <FACILITYID>{ data($choice/FACILITYID) }</FACILITYID> and other tags

                • 5. Re: For-loop with counter variable in xquery in OSB
                  RAMMII

                  I tried below code to compare more fields. It worked. Thanks for your help.

                   

                  <InputParameters>

                              {

                                  for $choice in $inputParameters1/choice               

                                   let $withSamePrimaryID := ($inputParameters1/choice[PRIMARYID eq $choice/PRIMARYID])                 

                                   let $withSamePrimaryID8 := ($inputParameters1/choice[FIRSTNAME eq $choice/FIRSTNAME])

                                   return

                                    <choice>

                                   {

                                   if(data($withSamePrimaryID[1]/ClaimID) = data($withSamePrimaryID8[1]/ClaimID)) then

                                   let $claimID:= $withSamePrimaryID[1]/ClaimID

                                   return

                                   <ClaimID>{$claimID}</ClaimID>                 

                                   else

                                   <ClaimID>{ data($choice/ClaimID) }</ClaimID>

                                   }

                                  other tags.