none
Calculating count of fields in record in Map RRS feed

  • Question

  • Hi,

    I am having BizTalk map , in source schema I am geeting Root -> Drivers -> ViolationCount fields.

    Divers is record field and can occur more then one times, suppose I am having multiple drivers and in one Drivers I am having multiple ViolationCount.

    I have applied looping funtoid on Drivers field and want to find out how many ViolationCount in one Drivers record.

    how to find it ?

    <Root>
    
    <Drivers>
    
    <Field1>dfg</Field1>
    
    <Field2>234</Field2>
    
    <Field3>fgty</Field3>
    
    <ViolationCount>Violation1</ViolationCount>
    
    <ViolationCount>Violation2</ViolationCount>
    
    <ViolationCount>Violation3</ViolationCount>
    
    
    </Drivers>
    
    
    <Drivers>
    
    <Field1>dfg</Field1>
    
    <Field2>234</Field2>
    
    <Field3>fgty</Field3>
    
    <ViolationCount>Violation1</ViolationCount>
    
    <ViolationCount>Violation2</ViolationCount>
    
    <ViolationCount>Violation3</ViolationCount>
    
    
    </Drivers>
    
    <Drivers>
    
    <Field1>dfg</Field1>
    
    <Field2>234</Field2>
    
    <Field3>fgty</Field3>
    
    <ViolationCount>Violation1</ViolationCount>
    
    <ViolationCount>Violation2</ViolationCount>
    
    <ViolationCount>Violation3</ViolationCount>
    
    
    </Drivers>
    
    
    </Root>
    


    Thanks and Regards, Nitin.

    Friday, March 3, 2017 8:06 AM

Answers

  • Hi Nitin,

    Within BizTalk there is a functoid called Record Count that will return the number of instances of a repeated record or repeated element that occur in a message instance. The input to this functoid is the record or element to be counted.

    Refer: https://msdn.microsoft.com/en-us/library/ee253826(v=bts.10).aspx


    Rachit Sikroria (Microsoft Azure MVP)

    Friday, March 3, 2017 8:51 AM
    Moderator
  • Hi Nitin,

    You can use XSLT to achieve this. When you give the Xpath of the element to be counted as input to count method in XSLT, give the index of 'Drivers' node as position in the Xpath to find out the number of elements in that particular occurrence of the 'Drivers' node as shown below.

    count(/Drivers[position()=$index]/ViolationCount)

    where $index=1 for the first occurrence

    if you need to find out for all occurrences, you will need to use looping.

    Regards,

    Pranaya.

    Friday, March 3, 2017 2:27 PM

All replies

  • Hi Nitin,

    Within BizTalk there is a functoid called Record Count that will return the number of instances of a repeated record or repeated element that occur in a message instance. The input to this functoid is the record or element to be counted.

    Refer: https://msdn.microsoft.com/en-us/library/ee253826(v=bts.10).aspx


    Rachit Sikroria (Microsoft Azure MVP)

    Friday, March 3, 2017 8:51 AM
    Moderator
  • You can use record count functoid:

    In XSL you can get it as : count(/Drivers/ViolationCount)


    Pi_xel_xar

    Blog: My Blog

    BizTalkApplicationDeploymentTool: BizTalk Application Deployment Tool/

    Friday, March 3, 2017 1:07 PM
    Answerer
  • Hi Nitin,

    You can use XSLT to achieve this. When you give the Xpath of the element to be counted as input to count method in XSLT, give the index of 'Drivers' node as position in the Xpath to find out the number of elements in that particular occurrence of the 'Drivers' node as shown below.

    count(/Drivers[position()=$index]/ViolationCount)

    where $index=1 for the first occurrence

    if you need to find out for all occurrences, you will need to use looping.

    Regards,

    Pranaya.

    Friday, March 3, 2017 2:27 PM
  • Hi Nitin,

    You can write inline XSLT to achieve this as Pranaya A mentioned in his proposed answer. I just implemented this solution and its working.

    

    Regards,

    Muhammad Kamal

    Monday, March 6, 2017 3:44 PM