<?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>Acepting only two types of extensions</title><link>https://community.appian.com/discussions/f/general/17595/acepting-only-two-types-of-extensions</link><description>I need help setting up the code to accept only two extensions. I got the below code from Appian. This way, it only accepts one, either PNG or JPG. How do I switch this so it can be accepting of PNG and JPG? validations: a!localVariables ( 
 local!invalidExtensions</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Acepting only two types of extensions</title><link>https://community.appian.com/thread/69353?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2019 20:42:34 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:4ba38442-085c-4c52-b00b-a88959598174</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;The only thing I know of that would do that is setting a value for the &lt;em&gt;maxSelections&lt;/em&gt; parameter.&amp;nbsp; For example, my original code snippet above allows me to upload multiple (i just double checked).&amp;nbsp; Did you change anything else?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Acepting only two types of extensions</title><link>https://community.appian.com/thread/69352?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2019 20:40:04 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:06f3a84a-6508-44bf-b934-ff78865bc3f4</guid><dc:creator>jarell13</dc:creator><description>&lt;p&gt;I see, that does make more sense. I got it to work with your logic example you provided. One more thing, do you happen to know how to get the upload button to accept multiple files. Before adding the validation, I was able to upload multiple files. Now, it only lets me upload one.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Acepting only two types of extensions</title><link>https://community.appian.com/thread/69351?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2019 19:56:04 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b747556c-4a2c-46bf-8aa9-047b3fba258c</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Double-checking your original code, I can confirm that just fixing the index() call seems to have been enough to make it work.&amp;nbsp; For what it&amp;#39;s worth &lt;span class="emoticon" data-url="https://community.appian.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1568231784604v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Acepting only two types of extensions</title><link>https://community.appian.com/thread/69350?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2019 19:53:34 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:38fa7eb8-b5da-4d91-9a87-7df530518b30</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;The requirement to have it spit out the list of files with invalid extensions makes it a little convoluted - a simpler validation message would be much easier to code and understand, FWIW.&lt;/p&gt;
&lt;p&gt;Anyway --&amp;nbsp;first off, there&amp;#39;s a mistake in your&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;i&gt;index()&lt;/i&gt;&amp;nbsp;function - you have 4 parameters (&lt;em&gt;fv!files&lt;/em&gt;, then name, then your &lt;em&gt;wherecontains()&lt;/em&gt;, then an empty set); so this wouldn&amp;#39;t work under any circumstances.&amp;nbsp; The correct way of writing this would be&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;i&gt;index(fv!files.name, ...)&lt;/i&gt;, which I believe is safe because the only time the validation message would attempt to evaluate, fv!files would have to be populated (and therefore have the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;i&gt;.name&lt;/i&gt;&amp;nbsp;property).&lt;/p&gt;
&lt;p&gt;Overall, though, my suggestion for you (after fixing the &lt;em&gt;index()&lt;/em&gt; function) is to front-load a bit more of your logic into local variables so that they&amp;#39;re understandable - in particular, the &lt;em&gt;wherecontains()&lt;/em&gt; call.&amp;nbsp; If we calculate the indices of the bad extensions ahead of time, the later &lt;em&gt;index()&lt;/em&gt; function becomes a lot more easy to understand.&amp;nbsp; For example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;a!localVariables(
  local!uploadedDoc,
  
  a!fileUploadField(
    value: local!uploadedDoc,
    saveInto: local!uploadedDoc,
    validations: a!localVariables(
      local!allowedExtensions: {&amp;quot;png&amp;quot;, &amp;quot;jpg&amp;quot;},

      local!invalidExtensions: difference(upper(fv!files.extension), { &amp;quot;PNG&amp;quot;, &amp;quot;JPG&amp;quot; }),
      
      local!badExtensionIndices: wherecontains(
        local!invalidExtensions,
        upper(fv!files.extension)
      ),

      if(
        not(rule!APN_isEmpty(local!invalidExtensions)), 
        &amp;quot;Attachments must be images. Remove: &amp;quot; &amp;amp;
        index(
          fv!files.name, /* this was the main error before */
          local!badExtensionIndices,
          {}
        ), 
        null()
      )
    )
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Let me know if you have any questions.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>