Resources for IT Professionals > Forums Home > BizTalk Server Forums > BizTalk Server General > Need to delete data in a perticular Element Field based on another Element Field's value
Ask a questionAsk a question
 

AnswerNeed to delete data in a perticular Element Field based on another Element Field's value

  • Thursday, November 12, 2009 5:36 PMScubaDrew Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello,

    I'm learning Biztalk in my free time, and am having trouble determining the right way to clear/delete the values in a particular element field based on the value of another element field, for a repeating record. 

    I've got my two Schema's defined, and am setup to do the transform in an Orchestration. Can someone point me towards a way I can clear the "SocialSecurityNumber" field out of all the records that have a member_type of "Dependent"

    Thank you very much for your time,

    Drew


Answers

  • Thursday, November 12, 2009 5:54 PMcallvishnu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    HI,

    The best way is to use XSLT call template by using script functoids.

    http://msdn.microsoft.com/en-us/library/aa561574(BTS.20).aspx

    By using if else in your xslt you can easily achieve this.


    Regards
    Vishnu
    Vishnu
    • Marked As Answer byScubaDrew Wednesday, November 18, 2009 9:10 PM
    •  
  • Friday, November 13, 2009 3:42 AMTariq Majeed Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    You can achieve this by using value mapping functoid (http://social.msdn.microsoft.com/Forums/en-US/biztalkgeneral/thread/ea48ca71-ad2c-4d52-91bb-4b57995dc42d) and logical not equal functoid (http://msdn.microsoft.com/en-us/library/ee267951(BTS.10).aspx).  The value mapping functoid accepts two parameters.  The first parameter is a boolean value and second is the value that will be passed to the output.  You add a logical Not equal and value mapping functoids to the map. Connect member_type as first parameter and type Dependent as second parameter to the logical not equal functoid.  Connect the output of this functoid to the value mapping functoid.  Then connect your social security node from source to value mapping functoid.  Connect the output of value mapping functoid to the social security node of your output schema.  

    The logical not functoid will only pass true value when your member_type is any value other than Dependent.  Similarly the value mapping functoid will output only when your member_type is any value other than Dependent.  You may have to use more than one value mapping functoids depending on your output schema.  Please post a sample out and input message if you have any issues doing this.

    Regards,

    Tariq Majeed


    Please mark it as answer if it helps
  • Thursday, November 19, 2009 3:57 PMTariq Majeed Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    The reason you are getting this error is the map is not generating the output element WorkAdd1 which is a mandatory element.  There can be two reasons:

    1.  The equal functoid is returning false value, so value mapping is not generating any output.
    2.  You have connected the inputs in wrong order. May be you have connected the WorkAdd1 first to value mapping and then you connected equal functoid.  In this case WorkAdd1 is your first parameter and equal functoid is second that is wrong.  Right click value mapping functoid and select configure inputs.  Verify that the input parameters are correct in order and change the order if it is wrong.  You can change the order by selecting the parameter and clicking the arrow button there.

    BTW why are you using concatenate functoid?

    Yesterday you asked the question to generate empty element node in case some condition is false.  Your exact requirement was as following:

    Problem:

    1. If member_type is not dependent, copy the SocialSecurityNumber from source to destination.
    2. Else generate an empty SocialSecurityNumber element.

    Solution:

    There are many ways to solve this issue.  I mentioned one using xslt call Template scripting which is perfectly correct solution.  

    But you can also solve this using ValueMapping functoids.  You need two value mapping functoids, one for if condition and the second one foe else. You already have done the if part, so I will just explain the else part.  In order to do the else part, add one logical Not functoid and one value mapping functoid.  Connect you logical functoid (equal, not equal or whaever you are using earlier for if part that is connected to your first value mapping functoid) to the Not functoid.  Connect the output of the Not functoid to second value mapping functoid as first parameter.  Right click this value mapping functoid and select Configure Functoid Inputs.  Select to insert new parameter, do not type anything in the constant field.  So the empty constant is your second parameter.  Connect this value mapping functoid to the SocialSecurityNumber element of output.

    I have tested this and it works.  You will get a warning, just ignore that.

    The logic is that at one point only one value mapping will generate output.  Let us say your condition is true (member_type is not equal to Dependent), the first conditional functoid (Logical Not Equal) will be true and your first value mapping functoid will copy the SocialSecurityNumber from source to destination.  The Not functoid will chnage True to false and the second value mapping will not generate any output.

    If your initial condition is false (member_type is equal to Dependent), the first conditional functoid (Logical Not Equal) will be false, so the first value mapping will not generate any output.  But the Not functoid will change false to true and your second value mapping will get true and as a result of that it will generate an empty output as second parameter is empty constant.

    Please try this and let me know if you have any issues.

    Regards,

    Tariq Majeed   

      

    Please mark it as answer if it helps
    • Marked As Answer byScubaDrew Thursday, November 19, 2009 6:15 PM
    •  

All Replies

  • Thursday, November 12, 2009 5:54 PMcallvishnu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    HI,

    The best way is to use XSLT call template by using script functoids.

    http://msdn.microsoft.com/en-us/library/aa561574(BTS.20).aspx

    By using if else in your xslt you can easily achieve this.


    Regards
    Vishnu
    Vishnu
    • Marked As Answer byScubaDrew Wednesday, November 18, 2009 9:10 PM
    •  
  • Thursday, November 12, 2009 8:04 PMScubaDrew Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thank you Vishnu,

    I'll try this as soon as I can get this problem resolved.


    I'll mark this as answered as soon as I know!

    Thanks,

    Drew
  • Friday, November 13, 2009 3:42 AMTariq Majeed Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    You can achieve this by using value mapping functoid (http://social.msdn.microsoft.com/Forums/en-US/biztalkgeneral/thread/ea48ca71-ad2c-4d52-91bb-4b57995dc42d) and logical not equal functoid (http://msdn.microsoft.com/en-us/library/ee267951(BTS.10).aspx).  The value mapping functoid accepts two parameters.  The first parameter is a boolean value and second is the value that will be passed to the output.  You add a logical Not equal and value mapping functoids to the map. Connect member_type as first parameter and type Dependent as second parameter to the logical not equal functoid.  Connect the output of this functoid to the value mapping functoid.  Then connect your social security node from source to value mapping functoid.  Connect the output of value mapping functoid to the social security node of your output schema.  

    The logical not functoid will only pass true value when your member_type is any value other than Dependent.  Similarly the value mapping functoid will output only when your member_type is any value other than Dependent.  You may have to use more than one value mapping functoids depending on your output schema.  Please post a sample out and input message if you have any issues doing this.

    Regards,

    Tariq Majeed


    Please mark it as answer if it helps
  • Saturday, November 14, 2009 10:44 PMScubaDrew Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thank you Tariq - I spent all day friday building a new virtual system with sql, vs 2008, and biztalk server - monday I should be able to try both of these methods and will report back on my success!

    thanks agian,

    Drew
  • Wednesday, November 18, 2009 9:12 PMScubaDrew Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Both methods recommended worked. I ended up using the logical and value mapping functoids since I could not easily re-use the custom script functoid. (no ability to copy and paste instances of it)

    thanks again guys,

    Drew
  • Wednesday, November 18, 2009 10:09 PMScubaDrew Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I spoke a little soon - when I use the value mapping functoid and run a test I get:

    The element 'MarathonStandard_Child1' has invalid child element 'HomeAdd1'. List of possible elements expected: 'WorkAdd1'.

    It appears that the when the false value is passed to the value mapping functoid it does not create any output and then the output mapping gets thrown off.

    I read this:
    Forcing the Creation of Empty Tags

    To force empty tags to be created, you can add a value in the Value property of the destination field or link a Concatenatefunctoid to the destination field. In BizTalk Server, it is possible to force the generation of empty tags by selecting the "<empty>" value in the Value property of the destination field. In this case the field will be created with the empty value.

     

    but I do not have the <empty> value, nor do I see a Value property in the destination field. I do have a "Default Value" but there is no dropdown.

  • Wednesday, November 18, 2009 11:42 PMTariq Majeed Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    You can easily do this by using inline xsl call template.  Please follow the following steps:

    1.  Add a scripting functoi, select inline xslt call template and copy the following code in the functoid:

    <xsl:template name="SSNCallTemplate">
    <xsl:param name="memberType" />
    <xsl:param name="SSN" />
    <xsl:element name="SocialSecurityNumber">
    <xsl:if test="$memberType!='Dependent'">
    <xsl:value-of select="$SSN" />
    </xsl:if>
    </xsl:element>
    </xsl:template>

    2.  Connect member_type field from source to scripting functoid as first parameter and Connect SocialSecurityNumber from source to scripting functoid as second parameter.

    3.  Connect the output of the scripting functoid to the SocialSecurityNumber element of destination.

    This should work.  I did a small POC using a test xml and it is working fine.  In case it does not work for you, then post your sample xml and I will check it.


    Regards,

    Tariq Majeed

    Please mark it as answer if it helps
  • Thursday, November 19, 2009 4:18 AMScubaDrew Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Tariq,

    I'd really like to figure out why a map that is working when the input element is linked directly to the output element suddenly throws the error:

    Map_HW_output.xml: error btm1046: Output validation error: The element 'MarathonStandard_Child1' has invalid child element 'HomeAdd1'. List of possible elements expected: 'WorkAdd1'.

    when connected using the "equal" functoid connected to the value mapping functoid. 

    Here is a picture of the working Page of the Map: http://picasaweb.google.com/oconnor.drew/ScreenCaptures#5405664001553163890

    Here is what the non-working functoid setup looks like: http://picasaweb.google.com/oconnor.drew/ScreenCaptures#5405663723804221410

    Sorry I'm having such a hard time with this,

    Drew 

    • Marked As Answer byScubaDrew Thursday, November 19, 2009 5:31 AM
    • Unmarked As Answer byScubaDrew Thursday, November 19, 2009 5:31 AM
    •  
  • Thursday, November 19, 2009 3:57 PMTariq Majeed Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    The reason you are getting this error is the map is not generating the output element WorkAdd1 which is a mandatory element.  There can be two reasons:

    1.  The equal functoid is returning false value, so value mapping is not generating any output.
    2.  You have connected the inputs in wrong order. May be you have connected the WorkAdd1 first to value mapping and then you connected equal functoid.  In this case WorkAdd1 is your first parameter and equal functoid is second that is wrong.  Right click value mapping functoid and select configure inputs.  Verify that the input parameters are correct in order and change the order if it is wrong.  You can change the order by selecting the parameter and clicking the arrow button there.

    BTW why are you using concatenate functoid?

    Yesterday you asked the question to generate empty element node in case some condition is false.  Your exact requirement was as following:

    Problem:

    1. If member_type is not dependent, copy the SocialSecurityNumber from source to destination.
    2. Else generate an empty SocialSecurityNumber element.

    Solution:

    There are many ways to solve this issue.  I mentioned one using xslt call Template scripting which is perfectly correct solution.  

    But you can also solve this using ValueMapping functoids.  You need two value mapping functoids, one for if condition and the second one foe else. You already have done the if part, so I will just explain the else part.  In order to do the else part, add one logical Not functoid and one value mapping functoid.  Connect you logical functoid (equal, not equal or whaever you are using earlier for if part that is connected to your first value mapping functoid) to the Not functoid.  Connect the output of the Not functoid to second value mapping functoid as first parameter.  Right click this value mapping functoid and select Configure Functoid Inputs.  Select to insert new parameter, do not type anything in the constant field.  So the empty constant is your second parameter.  Connect this value mapping functoid to the SocialSecurityNumber element of output.

    I have tested this and it works.  You will get a warning, just ignore that.

    The logic is that at one point only one value mapping will generate output.  Let us say your condition is true (member_type is not equal to Dependent), the first conditional functoid (Logical Not Equal) will be true and your first value mapping functoid will copy the SocialSecurityNumber from source to destination.  The Not functoid will chnage True to false and the second value mapping will not generate any output.

    If your initial condition is false (member_type is equal to Dependent), the first conditional functoid (Logical Not Equal) will be false, so the first value mapping will not generate any output.  But the Not functoid will change false to true and your second value mapping will get true and as a result of that it will generate an empty output as second parameter is empty constant.

    Please try this and let me know if you have any issues.

    Regards,

    Tariq Majeed   

      

    Please mark it as answer if it helps
    • Marked As Answer byScubaDrew Thursday, November 19, 2009 6:15 PM
    •  
  • Thursday, November 19, 2009 10:13 PMScubaDrew Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Thank you Tariq adding the logical not functoid and value mapping worked. I understand why it did not work with out it now.

    I added the concatenate functoid after reading http://msdn.microsoft.com/en-us/library/aa559723(BTS.10).aspx which suggested:

    "To force empty tags to be created, you can add a value in the Value property of the destination field or link a Concatenate functoid to the destination field."

    Also, I've successfully scripted this with the following VB code:

    Public Function OnlyOutputIfMemberType00(ByVal param1 As String, ByVal param2 As String) As String
      if param1 = "00" then 
        Return param2
       else 
        return ""
       end if
    End Function
    

    Thank you for your continued assistance!

    Drew