<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Call a rule by his name (text)</title><link>https://community.appian.com/discussions/f/rules/19403/call-a-rule-by-his-name-text</link><description>I need to create a rule containing other rules and execute them based on input. 
 To make it generic and durable, the intention is to never have to modify the upper rule and only create the new rules that arise according to the needs. 
 Perhaps now the</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Call a rule by his name (text)</title><link>https://community.appian.com/thread/75938?ContentTypeID=1</link><pubDate>Wed, 12 Aug 2020 19:15:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ef003253-9b63-43e9-ab71-1ed8cb125e8d</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;I second this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call a rule by his name (text)</title><link>https://community.appian.com/thread/75937?ContentTypeID=1</link><pubDate>Wed, 12 Aug 2020 19:07:18 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:de74e57d-f3b9-4369-81d8-69bfe8daec8b</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;I strongly recommend that you do not use this function - it is unsupported and there is no guarantee that it will behave how you expect.&lt;/p&gt;
&lt;p&gt;Instead, I&amp;#39;d recommend thinking about whether you could create an expression rule for this that could work as a template. For example, suppose that you have several functions that you want to call on demand - the simple case I&amp;#39;m thinking of is whether you want to apply cleanwith or stripwith to a value. It&amp;#39;s actually possible to store a function in a local variable that can be called on demand. In this case, I created a dictionary with a name and the function to call. Then, if I provide the input for the correct function short name (clean or strip), it will call the corresponding function with the parameters I provide below.&lt;/p&gt;
&lt;p&gt;(Of course, there&amp;#39;s even simpler ways to set this up for this basic case - a simple if() statement would also work. However, this demonstrates how to store a function in a local variable and call it on demand.)&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/640x240/__key/communityserver-discussions-components-files/15/function-called.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!functions: {
    {name: &amp;quot;Clean&amp;quot;, function: fn!cleanwith},
    {name: &amp;quot;Strip&amp;quot;, function: fn!stripwith}, 
  },
  if(
    contains(touniformstring(local!functions.name), ri!functionName),
    displayvalue(
      ri!functionName,
      touniformstring(local!functions.name),
      local!functions.function,
      null
    )
    (
      ri!text,
      ri!withCharacters
    ),
    ri!text
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call a rule by his name (text)</title><link>https://community.appian.com/thread/75936?ContentTypeID=1</link><pubDate>Wed, 12 Aug 2020 17:26:02 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7a55c65c-54d5-4237-af05-57e3135ff9b8</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;There is an &lt;a href="/discussions/f/rules/4246/is-there-a-way-to-convert-a-string-to-evaluable-sail-expression-i/15169#15169"&gt;unlisted function&lt;/a&gt; (therefore not officially supported, endorsed or even acknowledged by Appian and not for use in anything that will ever see a Production system) that does something like what it sounds like you&amp;#39;re asking for.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call a rule by his name (text)</title><link>https://community.appian.com/thread/75930?ContentTypeID=1</link><pubDate>Wed, 12 Aug 2020 16:23:29 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:344e2935-0f01-4095-980a-4e6896f267da</guid><dc:creator>vikrams247</dc:creator><description>&lt;p&gt;Try with nested foreach. Try by replacing doforeach to a!foreach in the above expression.&lt;/p&gt;
&lt;p&gt;Like &lt;/p&gt;
&lt;p&gt; &amp;nbsp;a!forEach(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;items: local!rulesArray,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;expresion: if(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;contains(ri!conditions, fv!item),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a!foreach(items:fv!item, expression:&amp;#123;based on your need&amp;#125;),&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call a rule by his name (text)</title><link>https://community.appian.com/thread/75902?ContentTypeID=1</link><pubDate>Wed, 12 Aug 2020 10:04:27 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a030f354-5b81-413f-a582-4dae08e28efa</guid><dc:creator>victorg98</dc:creator><description>&lt;p&gt;Maybe I didn&amp;#39;t explain well.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;I copy here the development that achieves my objective.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;a!localVariables(&lt;/em&gt;&lt;br /&gt; &lt;br /&gt;&lt;em&gt;&amp;nbsp; local!rulesArray: rule!getRulesFromDB(),&lt;/em&gt;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;&lt;em&gt;&amp;nbsp; {&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; a!forEach(&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; items: local!rulesArray,&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; expresion: if(&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; contains(ri!conditions, fv!item),&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; doforeach(fv!item,{ri!inputs}),&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; null)&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; )&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; }&lt;/em&gt;&lt;br /&gt;&lt;em&gt;)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;doforeach function is deprecated, can you think of alternatives? THANK YOU!!&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;In DB I have the names of the rules that I want to execute and when new rules appear to cover new needs, their names are added to that DB table.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>