Alpha Video Training
Results 1 to 26 of 26

Thread: Client Side Conditional Format Syntax To Obtain File Extension

  1. #1
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Client Side Conditional Format Syntax To Obtain File Extension

    I have a UX component with a List control.

    The list has a dynamic image that displays the correct icon for a given file extension. ie) filename.pdf displays a pdf icon, etc.
    The filename is stored in a reference field called 'Notes'

    This is all working fine using server-side conditional formatting with Xbasic code like this:
    Code:
    right(Notes,3)="PDF"
    This parses out the right 3 characters of the filename to derive the extension.

    Server-Side_Cond_Format.png

    BUT

    I would like to use client-side conditional formatting (javascript) as I think this will be much faster than doing it server-side.
    I'm stuck on how to get the extension from the filename using client-side conditional formatting.

    Is anyone able to point me in the right direction?
    Last edited by iRadiate; 08-19-2019 at 04:23 PM. Reason: typo
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  2. #2
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,355

    Default Re: Client Side Condiional Format Syntax To Obtain File Extension

    Quote Originally Posted by iRadiate View Post
    I have a UX component with a list.

    The list has a dynamic image that displays the correct icon for a given file extension. ie) filename.pdf displays a pdf icon, etc.
    The filename is stored in a reference field called 'Notes'

    This is all working fine using server-side conditional formatting with Xbasic code like this:
    Code:
    right(Notes,3)="PDF"
    This parses out the right 3 characters of the filename to derive the extension.

    Server-Side_Cond_Format.png

    BUT

    I would like to use client-side conditional formatting (javascript) as I think this will be much faster than doing it server-side.
    I'm stuck on how to get the extension from the filename using client-side conditional formatting.

    Is anyone able to point me in the right direction?
    I'm not a javascript expert, but I think this code will help.
    The entry for your clientside condition would then be something like getext(notes) = "xlsx".
    You might have to play with the = signs and quote marks.

    Code:
    function getext(strdata) {
      var str = strdata;
      var n = str.lastIndexOf('.');  
      var res = str.slice(n+1);
      return res;
    }

  3. #3
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Re: Client Side Condiional Format Syntax To Obtain File Extension

    Hi Gregg, thanks for your suggestion.
    With client-side conditional image for the list, the syntax requires data.fieldname

    Following that requirement, I have this:
    getExt(data.Notes)=='PDF'

    And the javascript function as this:
    Code:
    function getExt(data.Notes) {
      var str == data.Notes;
      var n == str.lastIndexOf('.');  
      var res == str.slice(n+1);
      return res;
    }
    It doesn't like this and generates errors. I thought it was the period in the data.fieldname so I tried javascript escaping the period like this, data/.fieldname but that won't work either.
    Still trying...
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  4. #4
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,355

    Default Re: Client Side Condiional Format Syntax To Obtain File Extension

    Stephen,
    The function should have worked as is, but you are using "==" where you should be using "=".
    Hopefully this image helps.
    2019-08-19_13-13-08.png
    Last edited by madtowng; 08-19-2019 at 02:15 PM. Reason: add image

  5. #5
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Re: Client Side Condiional Format Syntax To Obtain File Extension

    Quote Originally Posted by madtowng View Post
    Stephen,
    The function should have worked as is, but you are using "==" where you should be using "=".
    Hopefully this image helps.
    2019-08-19_13-13-08.png
    Pretty sure client-side javascript is double equals and single quotes. At least according to Alpha's help button ...

    Syntax.png

    I did try both ways, but I'm getting syntax errors and getExt() not defined. I 'think' the data. prefix in the fieldname is messing things up.
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  6. #6
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,355

    Default Re: Client Side Condiional Format Syntax To Obtain File Extension

    Here's the component I'm using for testing.
    Attached Files Attached Files

  7. #7
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Gregg,

    My scenario is different than your component, I'm trying to do this in a List control using the dynamic image property conditional image. Hence, the syntax to get the list data client-side being data.fieldname
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  8. #8
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,355

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Ok Stephen,

    I finally found some bingery that produces the desired effects on a list control.

    2019-08-19_21-26-50.png

  9. #9
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Can I see said bingery
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  10. #10
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    I think Alpha may be limiting what can be done inside the Conditional Image javascript expression. Nothing I do here on the client-side condition seems to work, I've tried:

    1. getExt(data.Notes)=='PDF'
    2. getExt(data.Notes)==\'PDF\'
    3. data.Notes.substr(data.Notes.length -3)=='PDF'
    4. data.Notes.slice(-3)=='PDF'
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  11. #11
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,355

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    I was frustrated that it wouldn't let me use any javascript function to make it happen,
    yet the list control was more than happy to use any column it had access to.

    So I reworked my sql select statement to create a virtual column.
    I use MySQL by default. If you use something else, there should be a way to mimic
    the same thing.

    I'm attaching a copy of my UX for convenience.

    Code:
    SELECT 
    	seq,
    	filenotes,
    	testcolor,
    	 RIGHT(filenotes, ( locate('.',  reverse(filenotes) )  - 1))  AS fileext 
    FROM listtest
    Attached Files Attached Files

  12. #12
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,355

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Just in case you're using MS Sql, I've tested this code, although
    you will need to make obvious adjustments.
    The image shows the results I got from the query.
    Out of curiosity I ran this on all 36 columns of the table, and requested the top 50000 rows to see
    how long the query would take. The image shows just under 3 seconds, which is about the same as
    it takes without the "virtual" column.
    Code:
    select top 1 filename, right(filename,CHARINDEX('.', reverse(filename))-1) AS fileExt
    from files
    where  doctypeid=1
    2019-08-20_8-55-30.png
    2019-08-20_9-01-43.png
    Last edited by madtowng; 08-20-2019 at 10:10 AM. Reason: one extra image

  13. #13
    Member jgrannis's Avatar
    Real Name
    Jeff Grannis
    Join Date
    Apr 2016
    Location
    New Iberia, LA
    Posts
    344

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Something like
    data.Notes.slice(-3)=='PDF'
    should work.

    Another option:
    data.Notes.indexOf('PDF')!=-1

    If neither work, maybe place a console.log of the data in the list's onBeforePopulate event to see if the values of the Notes fields really look like you are expecting. Compare to the values in the data after the list is populated to see if some built-in Alpha code is transforming the filename at some point after onBeforePopulate (are the filenames in the Notes field just some simple static text representing filenames or are they involved in some file synch mechanism of the list control?).

    Additional remark:
    I believe if you go the route of calling a function, the function should determine equality or whatever and then simply return true or false; not have the function return a value to then later try to perform some equality test.
    Last edited by jgrannis; 08-20-2019 at 10:59 AM.

  14. #14
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,355

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Quote Originally Posted by jgrannis View Post
    Something like
    data.Notes.slice(-3)=='PDF'
    should work.

    Another option:
    data.Notes.indexOf('PDF')!=-1

    If neither work, maybe place a console.log of the data in the list's onBeforePopulate event to see if the values of the Notes fields really look like you are expecting. Compare to the values in the data after the list is populated to see if some built-in Alpha code is transforming the filename at some point after onBeforePopulate (are the filenames in the Notes field just some simple static text representing filenames or are they involved in some file synch mechanism of the list control?).

    Additional remark:
    I believe if you go the route of calling a function, the function should determine equality or whatever and then simply return true or false; not have the function return a value to then later try to perform some equality test.
    Hi Jeff,
    Part of the problem is the list control apparently works only with <column name> == '<something>' (see image).
    I like your thought of the function should return true or false, but then how do you determine if the extension
    is doc, xls, or txt ?

    2019-08-20_9-59-26.png

  15. #15
    Member jgrannis's Avatar
    Real Name
    Jeff Grannis
    Join Date
    Apr 2016
    Location
    New Iberia, LA
    Posts
    344

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Oh, I was trying it with adding a Dynamic Image and then configuring the "Image definition" in Dynamic Image Properties.
    I don't think that Client-side Conditional style on a list Label control type is what he was looking for.

  16. #16
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,355

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Whether it's the label control or a dynamic image, the condition still must evaluate to true,
    and in this case, needs to identify what the file extension is.
    I've attached images to show the definition of the dynamic image , it's results, and the
    component I'm using to do the testing.

    2019-08-20_10-47-34.png
    2019-08-20_10-48-25.png
    Attached Files Attached Files

  17. #17
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Quote Originally Posted by jgrannis View Post
    Something like
    data.Notes.slice(-3)=='PDF'
    should work.
    Jeff, you would think so but it doesn't.

    Quote Originally Posted by jgrannis View Post
    Another option:
    data.Notes.indexOf('PDF')!=-1
    Neither does this.

    Quote Originally Posted by jgrannis View Post
    If neither work, maybe place a console.log of the data in the list's onBeforePopulate event to see if the values of the Notes fields really look like you are expecting. Compare to the values in the data after the list is populated to see if some built-in Alpha code is transforming the filename at some point after onBeforePopulate (are the filenames in the Notes field just some simple static text representing filenames or are they involved in some file synch mechanism of the list control?).
    The list does return the expected referenced file path. I can put the field in the list and the path is there.

    Quote Originally Posted by jgrannis View Post
    Additional remark:
    I believe if you go the route of calling a function, the function should determine equality or whatever and then simply return true or false; not have the function return a value to then later try to perform some equality test.
    Thanks, I never thought of this, I'll have to look further into this option.
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  18. #18
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Quote Originally Posted by madtowng View Post
    Just in case you're using MS Sql, I've tested this code, although
    you will need to make obvious adjustments.
    The image shows the results I got from the query.
    Out of curiosity I ran this on all 36 columns of the table, and requested the top 50000 rows to see
    how long the query would take. The image shows just under 3 seconds, which is about the same as
    it takes without the "virtual" column.
    Code:
    select top 1 filename, right(filename,CHARINDEX('.', reverse(filename))-1) AS fileExt
    from files
    where  doctypeid=1
    2019-08-20_8-55-30.png
    2019-08-20_9-01-43.png
    Gregg, this might be the way to go. I'm still playing around with this, I've had to tweak the MS-SQL query a bit but this gives me the extension correctly:

    Code:
     ,RIGHT(Notes,LEN(Notes)-CHARINDEX('.',Notes)) AS FileExt
    I might still need to play with it a bit to make sure filenames containing more than one '.' are considered.

    Thank you both for the suggestions, this has been way more difficult than I expected but I think I'm getting there
    It is so easy using server-side code.
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  19. #19
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,355

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Stephen,
    Glad to hear we got things on the right track. I absolutely agree that server-side is so much easier,
    and to be honest, the primary reason I've been willing to sacrifice speed.
    If you need help or explanation of anything I've provided, feel free to contact me. This obviously
    gets me to generate solutions for problems I hadn't considered.

  20. #20
    Member jgrannis's Avatar
    Real Name
    Jeff Grannis
    Join Date
    Apr 2016
    Location
    New Iberia, LA
    Posts
    344

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Simple all client-side example.

    dynImage.a5wcmp

  21. #21
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,355

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Jeff,
    You obviously know more about javascript than most of us.
    With that said, how would you write it to get that actual extension of
    a filename 'c:/aafiles/invoice.xlsx.pdf' ?

  22. #22
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Quote Originally Posted by jgrannis View Post
    Simple all client-side example.

    dynImage.a5wcmp
    Jeff, this works in your simple component but generates a script error when the data is being pulled from SQL.

    Script Error.png
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  23. #23
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Okay, I have this working using Gregg's virtual SQL column method.

    To Summarize:

    1. In the SQL Query create a virtual column to extract the file extension. ie) 'FileExt'

    Query.png

    2. Add the virtual column to the list layout and hide it.

    3. For the list dynamic image, reference the 'FileExt' field directly in the client-side conditional image code.

    Conditional Image.png

    Result:

    Result.png


    Thanks Gregg & Jeff for your ideas and your help. Wouldn't have got it without your help!
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  24. #24
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    As a quick follow up,

    I found a SQL Query method on Stack Overflow that handles filenames with multiple '.' ie) my.filename.pdf ==> returns pdf
    I've tested this and it works great for MS-SQL.

    Code:
    (CASE WHEN Notes like '%.%'
             THEN REVERSE(left(REVERSE(Notes), CHARINDEX('.', REVERSE(Notes))- 1))
             ELSE ''
    END) AS FileExt


    Turn off Portable SQL in Alpha
    Last edited by iRadiate; 08-21-2019 at 09:02 AM. Reason: Correction
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  25. #25
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,355

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Hi Stephen,

    That's essentially the code I put in post #12, the biggest difference being the Top 1 I forgot to take
    out from my test (I didn't want 15 years worth of results).

  26. #26
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Re: Client Side Conditional Format Syntax To Obtain File Extension

    Gregg,

    Yes, it is. Sorry, the thread is getting a bit long and my mind is getting a bit short
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

Similar Threads

  1. Client Side syntax - IMAGE - definitions-conditional
    By CharlesParker in forum Mobile & Browser Applications
    Replies: 2
    Last Post: 01-29-2017, 10:17 AM
  2. Client side format Last Name f_upper()?
    By Keith Hubert in forum Application Server Version 11 - Web/Browser Applications
    Replies: 8
    Last Post: 12-17-2012, 11:46 PM
  3. client side calculated field syntax
    By bob9145 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 2
    Last Post: 03-27-2011, 05:03 PM
  4. Howto set Client-side Date Format?
    By René Stout in forum Application Server Version 10 - Web/Browser Applications
    Replies: 7
    Last Post: 07-04-2010, 11:16 AM
  5. Client-side formatting syntax question
    By Peter.Wayne in forum Application Server Version 10 - Web/Browser Applications
    Replies: 3
    Last Post: 04-20-2010, 10:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •