There is a way, provided the required information is available at the time the rule is created.<br><br>There is a detailed section in the Expert manual explaining how to call template expansion with either a Collection of Map objects or a Collection of JavaBean objects. Taking beans, you would have<br>
<br>ServiceBean( String name, String value )<br>String getName<br>String getValue<br>String getType(){<br>   if( &quot;AAA&quot;.equals( value ) ) return &quot;Type1&quot;;<br>   if( &quot;XYZ&quot;.equals( value ) ) return &quot;Type2&quot;;<br>
   ...<br>}<br><br>You create a collection of such Objects, and call the expander for a template like this:<br><br>rule &quot;DC_@{row.rowNumber}&quot; 
  <br>when <br>    $service: Service(name == &quot;@{service}&quot;, value == 
  &quot;@{value}&quot;) <br>    $riskType: RiskType() <br>then <br>    
  $riskType.setName(&quot;@{type}&quot;); <br><div>    
  $riskType.setAtt(0,&quot;@{value}&quot;); <br>end </div><br>-W<br><br><br><br><div class="gmail_quote">2011/6/1 ChrisMu <span dir="ltr">&lt;<a href="mailto:christopher.mullard@credit-suisse.com">christopher.mullard@credit-suisse.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">




<div dir="ltr" align="left"><span><font face="Arial" size="2" color="#0000ff">So in essence, there&#39;s no way to use a function to insert a 
string literal into a rule from a template?</font></span></div><br>
<div dir="ltr" lang="en-us" align="left">
<hr>
<font face="Tahoma" size="2"><b>From:</b> FrankVhh [via Drools] 
[mailto:<a href="http://user/SendEmail.jtp?type=node&amp;node=3009838&amp;i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>] <br><b>Sent:</b> 31 May 
2011 17:20<br><b>To:</b> Mullard, Christopher<br><b>Subject:</b> RE: Smart 
Templates<br></font><br></div>
<div></div>But then that would call the service.getType() method when the rule 
is <br>run wouldn&#39;t it? <br>-&gt; Yes <br>  <br>I&#39;m trying create explicit, 
simple rules to avoid doing extra work when <br>running data through them. 
<br>-&gt; OK, in essence, I like that :-) <br>  <br>How would you use a 
rule to set the value within another rule? <br>-&gt; I am not sure that I follow 
you here... <br>If you want to avoid to execute the getType()-service at rule 
execution, then you would need to add an attribute name to your object, and call 
getType() before creating the rules. <br><br>Alternatively, you can insert an 
intermediate value whose value will be set by another rule and then use this 
intermediate value in your DC rules. <br><br>When <br>Service(value = &quot;AAA&quot;) 
<br>Then <br>String name = &quot;Type1&quot;; <br>insert(name); <br><br>Something like 
this... but make sure not to create a loop :-) <br><br>Regards, <br>Frank 
<br><br>
<blockquote style="border-left: 2px solid rgb(204, 204, 204); padding: 0px 1em;">
  <div>
  <div style="font-weight: bold;">ChrisMu wrote:</div>
  <div>But then that would call the 
  service.getType() method when the rule is <br>run wouldn&#39;t it? <br>  
  <br>I&#39;m trying create explicit, simple rules to avoid doing extra work when 
  <br>running data through them. <br>  <br>How would you use a rule to set 
  the value within another rule? <br>  <br>Thanks <br>Chris 
  <br><br>________________________________ <br><br>From: FrankVhh [via Drools] 
  <br>[mailto:<a href="http://user/SendEmail.jtp?type=node&amp;node=3006773&amp;i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>] <br>Sent: 31 May 
  2011 16:48 <br>To: Mullard, Christopher <br>Subject: Re: Smart Templates 
  <br><br><br>Hi, <br><br>The way I see it, this is the way your template should 
  look like. I do <br>not see the need to use eval() at all. <br><br>rule &quot;DC_0&quot; 
  <br>when <br>    $service: Service(name == &quot;@{service}&quot;, value == 
  &quot;@{value}&quot;) <br>    $riskType: RiskType() <br>then <br>    
  $riskType.setName($service.getType(&quot;@{value}&quot;)); <br>    
  $riskType.setAtt(0,&quot;@{value}&quot;); <br>end <br><br>I am assuming that RiskType is 
  already inserted in WM, but you could <br>just as well create a new object in 
  the then-part of the rule. <br><br>In stead of using the java-function to 
  determine the name, you might <br>actually just as well create an other rule 
  that sets the name according <br>to the value, thus putting the entire 
  decision logic in rules. <br><br>Hope this helps. <br><br>Regards, <br>Frank 
  <br><br><br><br>        ChrisMu wrote: <br>    
      Hi, <br>        <br>      
     I&#39;m trying to get a template (.drt) to generate 2 rules (.drl) 
  <br>from 2 datasets but by doing a little bit more work than direct 
  <br>substitution. <br>        <br>      
    Data (service,value): <br>        DC, AAA 
  <br>        DC, XYZ <br>        
  <br>        Idea for the template - if value is of type1 
  then create Type <br>object with &#39;Type1&#39; as name. If value is of type2, use 
  &#39;Type2&#39; as name: <br>        <br>      
    rule &quot;DC_@{row.rowNumber}&quot; <br>        when 
  <br>            Service(name == &quot;DC&quot;)   
    <br>        then <br>        
      Type.setName(eval(Service.getType(@{value}))) <br>    
          Type.setAtt(0,@{value}) <br>      
    end template <br>        <br>      
    eval(Service.getType(@{arg0})) should take &#39;AAA&#39; or &#39;XYZ&#39; etc as 
  <br>arg and return a string Type1/Type2 etc. <br>        
  <br>        This would then generate 2 rules that look 
  like: <br>        <br>        rule 
  &quot;DC_0&quot; <br>        when <br>        
      Service(name == &quot;DC&quot;, value == &quot;AAA&quot;)     <br>  
        then <br>            
  RiskType.setName(&quot;Type1&quot;) <br>            
  RiskType.setAtt(0,&quot;AAA&quot;) <br>        <br>    
      rule &quot;DC_1&quot; <br>        when <br>  
            Service(name == &quot;DC&quot;, value == &quot;XYZ&quot;) 
      <br>        then <br>      
        RiskType.setName(&quot;Type2&quot;) <br>        
      RiskType.setAtt(0,&quot;XYZ&quot;) <br>        
  <br>        ...is this possible at all? I&#39;m trying to 
  avoid the eval step <br>being done in the actual rule (.drl) . <br>  
        <br>        Thanks <br>    
      <br>        Chris 
  <br><br><br><br>________________________________ <br><br>If you reply to this 
  email, your message will be added to the discussion <br>below: <br><a href="http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3006589.html" rel="nofollow" link="external" target="_blank">http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3006589.html</a><br>
<br>To 
  unsubscribe from Smart Templates, click here <br>&lt;<a href="http://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubs" rel="nofollow" link="external" target="_blank">http://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubs</a><br>
cribe_by_code&amp;node=3006479&amp;code=Y2hyaXN0b3BoZXIubXVsbGFyZEBjcmVkaXQtc3Vp 
  <br>c3NlLmNvbXwzMDA2NDc5fDE5NzczMDY1MzE=&gt; . 
  <br><br>=============================================================================== 
  <br>Please access the attached hyperlink for an important electronic 
  communications disclaimer: <br><a href="http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html" rel="nofollow" link="external" target="_blank">http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html</a>  
  <br>=============================================================================== 
  </div></div></blockquote><br><br>
<hr noshade size="1" color="#cccccc">

<div style="font-family: tahoma,geneva,helvetica,arial,sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal; color: rgb(68, 68, 68);">

<div style="font-weight: bold;">If you reply to this email, your message will be 
added to the discussion below:</div><a href="http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3006773.html" rel="nofollow" link="external" target="_blank">http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3006773.html</a> 
</div>
<div style="margin-top: 0.4em; font-family: tahoma,geneva,helvetica,arial,sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 11px; line-height: normal; font-size-adjust: none; font-stretch: normal; color: rgb(102, 102, 102);">
To 
unsubscribe from Smart Templates, <a rel="nofollow" link="external">click 
here</a>. </div> <br><p class="MsoNormal"><span style="font-size: 8pt; font-family: Courier;" lang="EN-US">==============================================================================<br>Please access the attached hyperlink for an important electronic communications disclaimer:<br>
<a href="http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html" rel="nofollow" link="external" target="_blank">http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html</a><br>==============================================================================</span></p>
 <br>


        
<br><hr width="300" align="left">
View this message in context: <a href="http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3009838.html" target="_blank">RE: Smart Templates</a><br>
Sent from the <a href="http://drools.46999.n3.nabble.com/Drools-User-forum-f47000.html" target="_blank">Drools: User forum mailing list archive</a> at Nabble.com.<br><br>_______________________________________________<br>

rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>