<?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>if (function)</title><link>https://community.appian.com/discussions/f/rules/17415/if-function</link><description>Can some one explain how the below function evaluates, appreciate your help in advance!! 
 if(true, false, false, true, false, 30, 40)</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: if (function)</title><link>https://community.appian.com/thread/95652?ContentTypeID=1</link><pubDate>Fri, 27 May 2022 20:30:48 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a571dedb-2766-44ea-8b77-d75242d5b498</guid><dc:creator>Matt</dc:creator><description>&lt;p&gt;HI mike, here is the section in question&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/15/pastedimage1653683356930v2.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/95650?ContentTypeID=1</link><pubDate>Fri, 27 May 2022 20:12:18 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1fc53c01-a46f-4747-95c1-f675844ca838</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Can you post a screenshot of exactly where and in what context this is used there?&amp;nbsp; I tried your link but wouldn&amp;#39;t be able to actually see the content in question without (presumably) enrolling in and then partially completing this course.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/95649?ContentTypeID=1</link><pubDate>Fri, 27 May 2022 19:28:16 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:88207208-890d-44c4-80ef-05cd21fc7d4b</guid><dc:creator>Matt</dc:creator><description>&lt;p&gt;Can appain employees explain why this is undocumented but used in the basic training build an application step4?&amp;nbsp; &lt;a href="https://academy.appian.com/#/online-courses/c1bd66f0-0a04-45a7-981f-b8cc0cd1e971"&gt;academy.appian.com/&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/68757?ContentTypeID=1</link><pubDate>Mon, 12 Aug 2019 13:29:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6460fc91-aa6f-4434-adbd-e54a359bef82</guid><dc:creator>Ajoy</dc:creator><description>&lt;p&gt;Thank you Peter, much appreciated!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/68657?ContentTypeID=1</link><pubDate>Wed, 07 Aug 2019 21:24:40 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ea19ab9b-c349-4b9f-98c7-405ae1567912</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;I strongly recommend against using the function in this way since Appian&amp;#39;s Engineering team&amp;nbsp;does not document it as supported syntax. Keep in mind that there is likely a reason it is not supported officially - maybe it works in 99% of scenarios but doesn&amp;#39;t work in one or two edge cases? It&amp;#39;s not worth depending&amp;nbsp;on a feature that isn&amp;#39;t documented.&lt;/p&gt;
&lt;p&gt;Instead, there are plenty of alternates that&amp;nbsp;could work if you are trying to perform an if/then/else. Plus, the beauty of SAIL is that you can create reusable rules that include the logic you need. Here&amp;#39;s an example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;choose(
  where(
    {
      ri!colorIndex = 1,
      ri!colorIndex = 2,
      ri!colorIndex = 3,
      true
    }
  )[1],
  &amp;quot;Red&amp;quot;,
  &amp;quot;Green&amp;quot;,
  &amp;quot;Blue&amp;quot;,
  &amp;quot;Something Else...&amp;quot;
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Or,&amp;nbsp;here&amp;#39;s&amp;nbsp;a reusable rule called rule!IfThenElse that you could call whenever you want an if/then/else statement:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;index(
  ri!results,
  where(
    append(ri!conditions, true)
  )[1],
  ri!elseResult
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Or there&amp;#39;s even a lot of scenarios where a decision rule would solve it for you.&lt;/p&gt;
&lt;p&gt;Either way, use the power that Appian&amp;nbsp;&lt;strong&gt;does&lt;/strong&gt; provide instead of trying to rely on functionality that isn&amp;#39;t documented.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/68649?ContentTypeID=1</link><pubDate>Wed, 07 Aug 2019 17:30:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f0895c7d-4ee4-46a5-8a5d-ca90c16872df</guid><dc:creator>davel001150</dc:creator><description>&lt;p&gt;I remember code I made one time that wound up with dozens of close parenthesis at the end.&lt;/p&gt;
&lt;p&gt;Unfortunately, you can get yourself into highly unreadable space either way when you need an if() to decide which of two if functions you need to run.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;if(
firstCondition = true,
if( secondCondition = true, &amp;quot;output&amp;quot;, &amp;quot;other output&amp;quot;),
if( thirdCondition = true, &amp;quot;something different&amp;quot;, &amp;quot;something completely diffferent&amp;quot;)
)

/*or equally valid*/

if(
firstCondition = true,
if ( secondCondition = true, &amp;quot;output, &amp;quot;other output&amp;quot;),
thirdCondition = true,
&amp;quot;something different&amp;quot;,
&amp;quot;something completely different&amp;quot;
) /*Wait....so the first one needs an if() all to itself but not the second one? Yep*/&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It just feels like there&amp;#39;s always going to be a way to make this painful to anyone who has to maintain your code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/68642?ContentTypeID=1</link><pubDate>Wed, 07 Aug 2019 15:41:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5cc220eb-3c3d-4a06-ada5-26de5bf20995</guid><dc:creator>Ajoy</dc:creator><description>&lt;p&gt;Thank you, Rob.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/68641?ContentTypeID=1</link><pubDate>Wed, 07 Aug 2019 15:40:50 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:332fded0-1c84-499c-ad3b-988affa7c21c</guid><dc:creator>Ajoy</dc:creator><description>&lt;p&gt;Thank you! Mike, it was really informative&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/68629?ContentTypeID=1</link><pubDate>Wed, 07 Aug 2019 14:14:53 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:79e6ed2f-46f7-4cfc-ac37-8807a64e705b</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Agreed - it&amp;#39;s used this way in at least a few places in a legacy application I&amp;#39;ve inherited, in a way that would be a pretty big pain to need to retroactively clean up.&amp;nbsp; I personally hope they&amp;#39;ll just make this functionality official, because all-in-all it&amp;#39;s a far less messy way of doing if/then/else functionality, as opposed to the traditional style of using infinite levels of nesting, which just looks nasty.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/68628?ContentTypeID=1</link><pubDate>Wed, 07 Aug 2019 14:12:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8d27b59f-2d2e-420d-b654-f85cd7242edc</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Well to be fair, I was describing how it *does work*, especially given the context of the original question.&amp;nbsp; That&amp;#39;s not to say whether it&amp;#39;s officially documented / supported /&amp;nbsp;&lt;em&gt;not&lt;/em&gt;&lt;span style="text-decoration:underline;"&gt;&lt;/span&gt; supported / etc.&amp;nbsp; I agree that anyone who uses this functionality should do so with caution.&lt;/p&gt;
&lt;p&gt;As an aside, I&amp;#39;d consider the error message you get when entering an invalid number of parameters fairly official:&lt;/p&gt;
&lt;p&gt;&lt;img height="78" src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/15/pastedimage1565186910588v1.png" width="403" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/68626?ContentTypeID=1</link><pubDate>Wed, 07 Aug 2019 13:56:02 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:280fc5da-4eae-48b4-9376-77c7cb53d91a</guid><dc:creator>davel001150</dc:creator><description>&lt;p&gt;Appian can go one of three ways about this:&lt;/p&gt;
&lt;p&gt;1. Fully document it&lt;/p&gt;
&lt;p&gt;2. Alter if() so it no longer behaves this way&lt;/p&gt;
&lt;p&gt;3. Do nothing and leave this question in Limbo&lt;/p&gt;
&lt;p&gt;Given the fact that at least some portion of Appian code out there, who knows how much, runs because someone figured out if() works this way, I would think option 2 might break an untold number of applications.&amp;nbsp; Appian wouldn&amp;#39;t want to do this, so I like option 1 and really like the odds of option 3 happening.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/68605?ContentTypeID=1</link><pubDate>Wed, 07 Aug 2019 07:37:33 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d029ee90-e5cd-457b-8257-59d1caf6a045</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;I&amp;#39;m with you, Gavin - if it&amp;#39;s not in the documentation then it is not officially supported. I&amp;#39;ve encountered a similar &amp;#39;bending&amp;#39; of the index() function where you can provide a list of values as way of navigating a tree-structure, and having asked Appian Engineering about this I had the same response - the documentation says it only takes 3 parameters&amp;nbsp;and that&amp;#39;s how far the official support will take you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/68604?ContentTypeID=1</link><pubDate>Wed, 07 Aug 2019 07:32:51 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:40a0cb69-3705-4f4a-a5c0-e6b2ab7b7a21</guid><dc:creator>Gavin Hume</dc:creator><description>&lt;p&gt;Is this a supported &amp;quot;feature&amp;quot; as it does not appear to be mentioned on the &lt;a href="https://docs.appian.com/suite/help/19.2/fnc_logical_if.html"&gt;help&lt;/a&gt; page?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/68598?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2019 21:44:11 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:32599989-0ff4-4c5c-a00a-04dee219a337</guid><dc:creator>Robert Shankin</dc:creator><description>[quote userid="3498" url="~/discussions/f/rules/17415/if-function"]if(true, false, false, true, false, 30, 40)&amp;nbsp;[/quote]
&lt;p&gt;This will return false.&lt;/p&gt;
&lt;p&gt;The function evaluates the first input - In your case this is &amp;quot;true&amp;quot;.&amp;nbsp; Since it evaluates to true, it returns the 2nd input.&amp;nbsp; The 3rd input would be returned if the 1st input evaluated to false.&lt;/p&gt;
&lt;p&gt;test this by changing the second input from &amp;quot;false&amp;quot; to &amp;quot;Appian&amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if (function)</title><link>https://community.appian.com/thread/68596?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2019 21:43:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5a9ac485-9485-4dd9-b23a-ca494b0ded4b</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;the if() function can handle if/else if/else functionality inherently.&amp;nbsp; If given more than 3 parameters (if/then/else), the subsequent odd-numbered parameters [except the final one] will each be evaluated as a new condition.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;if(
  ri!colorIndex = 1,
  &amp;quot;Red&amp;quot;,
  
  ri!colorIndex = 2,
  &amp;quot;Green&amp;quot;,
  
  ri!colorIndex = 3,
  &amp;quot;Blue&amp;quot;,
  
  &amp;quot;Something else...&amp;quot;
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;For example, the above code will evaluate to &amp;quot;Red&amp;quot; for an input of 1, &amp;quot;Green&amp;quot; for an input of 2, &amp;quot;Blue&amp;quot; for an input of 3, and for any other input value, it will return the default return value of &amp;quot;Something else...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: as mentioned down-thread, this functionality is not&amp;nbsp;&lt;em&gt;officially&lt;/em&gt; supported or documented, so use it with caution if at all. (/edit)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>