none
How to implement filter/search in Business Rule Engine? RRS feed

  • Question

  • I have a message structure like:

    <Root>
      <Name>Paul</Name>
      <Age>20</Age>
      <Prizes>
        <Prize>
          <Code>0020</Code>
          <Description>10% discount expires 16th March</Description>
          <Category>A</Category>
          <Enabled>false</Enabled>
        </Prize>
        <Prize>
          <Code>0010</Code>
          <Description>15% discount expires 26th March</Description>
          <Category>A</Category>
          <Enabled>false</Enabled>
        </Prize>
        <Prize>
          <Code>0035</Code>
          <Description>5% discount expires 16th April</Description>
          <Category>B</Category>
          <Enabled>false</Enabled>
        </Prize>
      </Prizes>
    </Root>

    How can I use business rule engine to find the 1st Prize's details, which is under Category A and Enabled is false? I am not sure if Business Rule Engine can do a loop thing and search for different conditions.

    What I expect to see the result is the rule engine can pick the 1st Prize which Code is 0020 and all it's details.

    Thank you.


    • Edited by Xiao Han Wednesday, March 21, 2012 4:36 AM typo and additional ifnroamtion
    Wednesday, March 21, 2012 1:40 AM

Answers

  • Hi Xiao,

    You can access the xpath in BRE by which you can look for specific node (e.g. first node in your case)

    xpath "/*[local-name()='Root']/Prizes/Prize[1]/Code" will select the Code from first node.

    Please refer to link below where Greg has explained it very well.

    http://social.msdn.microsoft.com/Forums/ar/biztalkgeneral/thread/2b3f1592-64a5-42a1-9111-909dda874b9b

    Also refer to link http://www.w3schools.com/xpath/xpath_syntax.asp for more details on implementing xpath filters.

    I hope this helps you.


    Thanks With Regards,
    Shailesh Kawade
    MCTS BizTalk Server
    Please Mark This As Answer If This Helps You.
    http://shaileshbiztalk.blogspot.com/

    • Marked as answer by Xiao Han Friday, March 23, 2012 2:53 AM
    Thursday, March 22, 2012 5:31 AM
  • Hi Shailesh,

    Do you mean

    In the XPath Selector, I have below after select the Code element from the 1st screenshot:

    /*[local-name()='Root' and namespace-uri()='http://BT.Schemas.Schema1']/*[local-name()='Prizes' and namespace-uri()='']/*[local-name()='Prize' and namespace-uri()='']

    So I need to change this to select the 1st Prize like:

    /*[local-name()='Root' and namespace-uri()='http://BT.Schemas.Schema1']/*[local-name()='Prizes' and namespace-uri()='']/*[local-name()='Prize' and namespace-uri()=''][1]


    Am I doing the right thing to use Xpath to define a new vocabulary in the fact explorer?



    • Edited by Xiao Han Thursday, March 22, 2012 10:07 PM
    • Marked as answer by Xiao Han Friday, March 23, 2012 2:53 AM
    Thursday, March 22, 2012 10:05 PM

All replies

  • You definitely can do this. See this article with sample, for example. There are much more.

    Leonid Ganeline [BizTalk MVP] BizTalkien: Advanced Questions: have fun - test your knowledge

    Wednesday, March 21, 2012 4:18 AM
    Moderator
  • You definitely can do this. See this article with sample, for example. There are much more.

    Leonid Ganeline [BizTalk MVP] BizTalkien: Advanced Questions: have fun - test your knowledge

    Thanks Leonid,

    So basically that solution is required to write .Net class to performance a customized function to lookup specific value, correct?

    Is there anyway I can just get the first prize details in order in BRE with built-in functions?

    Wednesday, March 21, 2012 4:45 AM
  • Hi Xiao,

    You should be able to do this with xpaths in BRE.

    Please refer very good arcticles from Charles & Richard below,

    http://geekswithblogs.net/cyoung/articles/90102.aspx

    http://seroter.wordpress.com/2007/03/19/fun-with-biztalk-xpath-and-namespaces/

    I think this will be helpful to implement your requirements.


    Thanks With Regards,
    Shailesh Kawade
    MCTS BizTalk Server
    Please Mark This As Answer If This Helps You.
    http://shaileshbiztalk.blogspot.com/

    Wednesday, March 21, 2012 5:34 AM
  • Hi,

    Are you doing only the search operation using Business Rule Engine? Or do you have some plans to compare some results in rule engine? If you are just searching for a Node based on some criterion then I would not use BRE for this (IMHO). I will simply use a .net class or may be store some config in SSO or .net config file.

    However use Xpath to get the value ,Links/Articles suggested by Leonid and Shailesh are ways to follow. 

    I hope it helps!


    HTH,
    Naushad Alam

    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer
    alamnaushad.wordpress.com |

    My new TechNet Wiki "BizTalk Server: Performance Tuning & Optimization"

    Wednesday, March 21, 2012 7:56 AM
    Moderator
  • Hi,

    Are you doing only the search operation using Business Rule Engine? Or do you have some plans to compare some results in rule engine? If you are just searching for a Node based on some criterion then I would not use BRE for this (IMHO). I will simply use a .net class or may be store some config in SSO or .net config file.

    However use Xpath to get the value ,Links/Articles suggested by Leonid and Shailesh are ways to follow. 

    I hope it helps!


    HTH,
    Naushad Alam

    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer
    alamnaushad.wordpress.com|

    My new TechNet Wiki "BizTalk Server: Performance Tuning & Optimization"

    What I want is find the 1st Prize in order under Prizes section, and set some value in the business rules.
    Wednesday, March 21, 2012 10:16 AM
  • Ok, Then I would suggest you to follow Leonid/Shailesh's suggestion.

    HTH,
    Naushad Alam

    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer
    alamnaushad.wordpress.com |

    My new TechNet Wiki "BizTalk Server: Performance Tuning & Optimization"

    Wednesday, March 21, 2012 10:32 AM
    Moderator
  • Hi Xiao,

    You should be able to do this with xpaths in BRE.

    Please refer very good arcticles from Charles & Richard below,

    http://geekswithblogs.net/cyoung/articles/90102.aspx

    http://seroter.wordpress.com/2007/03/19/fun-with-biztalk-xpath-and-namespaces/

    I think this will be helpful to implement your requirements.


    Thanks With Regards,
    Shailesh Kawade
    MCTS BizTalk Server
    Please Mark This As Answer If This Helps You.
    http://shaileshbiztalk.blogspot.com/

    Thanks for your reply,

    But I didn't get how these 2 articles would be helpful to my problem. The only issue for me at the moment is, for the repeating Prize, BRE treat them the same, no order, but for my solution, I need to always get the Code value 0020 from the 1st Prize.

    Would you be more specific, please? I didn't have experience of using Xpath in BRE.

    Wednesday, March 21, 2012 12:54 PM
  • Correct me if I am wrong, my understanding for BRE is that it's looking for a pattern to match all the conditions, so the 3 prizes in my example message basically are the same to BRE, cause no order is defined in the pattern kind of rule engine. So BRE can not tell which prize is the 1st one from the 3 prizes.

    The solution Leonid suggested is using a .Net class to do the job.I didn't get how to use xPath in BRE to do searching. Please give any example?

    Thank you.

    Thursday, March 22, 2012 12:59 AM
  • Hi Xiao,

    You can access the xpath in BRE by which you can look for specific node (e.g. first node in your case)

    xpath "/*[local-name()='Root']/Prizes/Prize[1]/Code" will select the Code from first node.

    Please refer to link below where Greg has explained it very well.

    http://social.msdn.microsoft.com/Forums/ar/biztalkgeneral/thread/2b3f1592-64a5-42a1-9111-909dda874b9b

    Also refer to link http://www.w3schools.com/xpath/xpath_syntax.asp for more details on implementing xpath filters.

    I hope this helps you.


    Thanks With Regards,
    Shailesh Kawade
    MCTS BizTalk Server
    Please Mark This As Answer If This Helps You.
    http://shaileshbiztalk.blogspot.com/

    • Marked as answer by Xiao Han Friday, March 23, 2012 2:53 AM
    Thursday, March 22, 2012 5:31 AM
  • Hi Shailesh,

    Do you mean

    In the XPath Selector, I have below after select the Code element from the 1st screenshot:

    /*[local-name()='Root' and namespace-uri()='http://BT.Schemas.Schema1']/*[local-name()='Prizes' and namespace-uri()='']/*[local-name()='Prize' and namespace-uri()='']

    So I need to change this to select the 1st Prize like:

    /*[local-name()='Root' and namespace-uri()='http://BT.Schemas.Schema1']/*[local-name()='Prizes' and namespace-uri()='']/*[local-name()='Prize' and namespace-uri()=''][1]


    Am I doing the right thing to use Xpath to define a new vocabulary in the fact explorer?



    • Edited by Xiao Han Thursday, March 22, 2012 10:07 PM
    • Marked as answer by Xiao Han Friday, March 23, 2012 2:53 AM
    Thursday, March 22, 2012 10:05 PM
  • Hi Shailesh,

    I tried your xPath, it works.

    Thank you.

    Friday, March 23, 2012 2:53 AM