Alpha Video Training
Results 1 to 16 of 16

Thread: getting Client-side filename function to work

  1. #1
    Member
    Real Name
    Edgar Solorio
    Join Date
    Nov 2012
    Posts
    65

    Default getting Client-side filename function to work

    Cant seem to get it to work.

    Clien-side filename set to function:fileName

    and in Javascript functions
    function fileName(){
    var fileName = {dialog.Object}.getValue('FileName');
    return encodeURIComponent(fileName);
    }

    and all I get are files name function_fineName

    Sadly I only have 5028 build 5088 so I hope its not just that its broken on this version.

  2. #2
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,491

    Default Re: getting Client-side filename function to work

    It's unclear what you're trying to do. What does "Client-side filename set to function:fileName" mean? Where is this being set... in what context?

    Your function code is a little bit dangerous. You have a control named FileName, a Javascript function named fileName, and a variable inside that function named fileName. That's a couple too many filenames for safety.

    I would write the function like this...

    Code:
    function getFileName(){
    	var fn = {dialog.Object}.getValue('FileName');
    	return encodeURIComponent(fn);
    }

  3. #3
    Member
    Real Name
    Edgar Solorio
    Join Date
    Nov 2012
    Posts
    65

    Default Re: getting Client-side filename function to work

    I will change the names, I did change them a few times but do not remember if i set them all to a different value at the same time.

    I am trying to set the name of a file being downloaded from the server (file was embedded into an sql filestream) using an on click event (button).


    EDIT:
    Just changed the function and the client-side file name property to function:getFileName; now just getting a file with this name: function_getFileName.

    Doesn't look like the property actually calls the function its just setting the name to whats typed there, but its supposed to be to set a dynamic file name i think.

    EDIT2:
    Also tried setting that property to ::getFileName and =::getFileName with similar results.
    Last edited by Archesr; 05-13-2019 at 01:26 AM.

  4. #4
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,491

    Default Re: getting Client-side filename function to work

    What Javascript is in your button on click event?

  5. #5
    Member
    Real Name
    Edgar Solorio
    Join Date
    Nov 2012
    Posts
    65

    Default Re: getting Client-side filename function to work

    action javascript file download (the premade items) https://documentation.alphasoftware....20Download.xml

    Sadly i cant use S3 as my version doesn't seem to work with it anymore, i have it setup on a SQL Filestream, the upload and download function works just cant seem to get this client side file name property to work as i think its intended.

  6. #6
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,491

    Default Re: getting Client-side filename function to work

    The syntax you're using for the Javascript function is not right. I'm not sure why you're putting the prefix "function" or anything else before your function name. Have another look at the doc... and at the in-line doc. Your Javascript function name should be just the function name with parens.

    Code:
    getFileName()
    Unfortunately, Alpha uses a number of different syntax variations throughout the UI. Sometimes it's just the name without parens, sometimes it's "javascript:functioname".

    I don't have build 5028, so double check the in-line doc. There should be a note at the bottom of the dialog you're in when setting the function name.

    Is your file sitting on your server? If so, where is it... specifically... what is the full path?

  7. #7
    Member
    Real Name
    Edgar Solorio
    Join Date
    Nov 2012
    Posts
    65

    Default Re: getting Client-side filename function to work

    The downloaded file is correct, just the function to set the name of the downloaded file is what is not working.

    The file is stored in an SQL FileStream EDIT: this works like an embedded file in an SQL table, the only one that uses the directory to the actual file itself is SQL. Both Upload and Download work well except for this client side file name property. EDIT: (For an embedded object, a system generated filename will be used.)

    I followed the text from the program version i am running and from the how to website, both being the same (see below)
    "To specify a Javascript function enter: function:nameOfYourJavascriptFunction."

    I have tried
    function:getFileName()
    function:getFileName
    :getFileName
    =:getFileName (knew this wasn't the right one because i think this is for an argument)(EDIT: i tried setting the argument to the field just in case, does not work that way ether)
    FUNCTION:getFileName()
    FUNCTION:getFileName
    Function:getFileName

    and i have just tried with the same result, it doesn't use the function it just names the file what i typed in this field.

    getFileName()
    =getFileName()

    I am not sure what i'm doing wrong, and i hope it's not that it just doesn't work on my version, as sadly for now i won't be able to upgrade to anything if this is fixed in a future version or in the current.


    Client-side filename
    Specify the default filename to use when saving the file on the user's computer. The user can override the suggested name. If you set the name to <Default>, then (for a linked file), the filename of the file on the server will be used. For an embedded object, a system generated filename will be used. If you specify a client-side filename with no extension, the extension of the file being downloaded will be used. TIP: You can call a Javascript function to dynamically generate the name of the client-side filename. To specify a Javascript function enter: function:nameOfYourJavascriptFunction. For example: function:setFilename, where 'setFilename' is the name of your Javascript function. The value returned by your Javascript function must be url encoded.

    EDITS- sorry I am not very good at explaining so i often feel the need to change what i said to reflect what i mean closer.
    Last edited by Archesr; 05-13-2019 at 04:21 PM.

  8. #8
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,491

    Default Re: getting Client-side filename function to work

    No... my mistake entirely... I misread, misunderstand what you wrote...

    Your Action Javascript, File Download, Client-side filename should be function:getFileName
    So, you have that right.

    Using FileStream, you are trying to download the file that SQL Server saves on your disk? E.g. is the filename something like...

    Code:
    "D:\UserFiles\Dummy-Documents\Dummy-Document\8e4c6374-9b01-4f3c-a909-47f0ea8de473\0347b2ac-3043-4cc3-a88d-8de2fa92535b\00000022-0000015e-0005"
    If so, then I think you need to provide double backslashes...

    Code:
    "D:\\UserFiles\\Dummy-Documents\\Dummy-Document\\8e4c6374-9b01-4f3c-a909-47f0ea8de473\\0347b2ac-3043-4cc3-a88d-8de2fa92535b\\00000022-0000015e-0005"
    In the Action, what is in the "Javascript" property... where you define the filename to download?

  9. #9
    Member
    Real Name
    Edgar Solorio
    Join Date
    Nov 2012
    Posts
    65

    Default Re: getting Client-side filename function to work

    Yea thats how FileStream is saving them on to the actual disk, however it acts as if the file is embedded into the table to AA gets a field with the blob data, it connects to the file just fine, but since the file name was changed to that GUID when uploaded to SQL i'm trying to get it to change the name on download to the correct file name that was stored on upload.

    So i'm not using something like telling it to download the GUID from the directory. Dont think thats actually possible with how SQL saves the file name and the GUID (they are not actually available outside of the SQL Server, AA wouldn't get the new file name it gave the file on the actual disk just the blob data of the file and the GUID and that's not the same as the file name on disk.)

    Here is a picture of how the button action javascript is placed and the file actually downloaded. (Ran it on the server hosting so it doesn't look like a pdf file on download but it is actually the correct file when opened)

    ScreenCap.jpg

    the function that is saved is the one you made for me earlier changing the names, i placed it on a calculated field to check that it gave the correct name and it is working, on the calculated field its only places as
    Code:
    getFileName()
    Code:
    function getFileName(){
    	var fn = {dialog.Object}.getValue('FileName');
    	return encodeURIComponent(fn);
    }
    Last edited by Archesr; 05-13-2019 at 08:54 PM.

  10. #10
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,491

    Default Re: getting Client-side filename function to work

    I can now duplicate what you're seeing. You have a data bound UX. You've added a "FileUpload/Download" control to your UX and this control is bound to your SQL Server FileStream Column... which is a BLOB. The image displays... and a download happens... and is the image... but Client-side filename does not work.

    I think you should report this to Alpha. I'm not sure if this is a bug... or just that the File Download Action does not work (entirely) with SQL Server FileStream. I wouldn't think fixing this... or getting it to work would be too much work. Something is going wrong when getting the Client-side Filename... as it's returning "function_getFileName". The Javacsript function is never being called.

    If you leave Client-side Filename as <Default>, then the Export Filename is picked up. This indicates that almost everything is working... except for the Client-side Filename.

  11. #11
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,491

    Default Re: getting Client-side filename function to work

    I've just tested with a MySQL Table and a longblob field. This issue has nothing to do with SQL Server and FileStream.

    The Client-side filename function never gets called. It doesn't matter if you include the parens on the function name... Alpha removes them from the Client-side filename property.

    The issue is that it's a bug. There have been other recent bugs in Alpha regarding the Javascript functions in File Upload. This is just the next one.

    Report this to Alpha. Alpha should test each one of these properties... instead of piecemeal fixing one at a time as it's found.

  12. #12
    Member
    Real Name
    Edgar Solorio
    Join Date
    Nov 2012
    Posts
    65

    Default Re: getting Client-side filename function to work

    Sigh thats what I was afraid of, I'll send a bug report, I'll try to find another way to get it to work for my version at least.

  13. #13
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,491

    Default Re: getting Client-side filename function to work

    If you can't move off 5028 then ask Alpha if they'd provide a hotfix for 5028. This bug is still in the current official release and in the latest pre-release.

  14. #14
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,279

    Default Re: getting Client-side filename function to work

    Quote Originally Posted by Davidk View Post
    I've just tested with a MySQL Table and a longblob field. This issue has nothing to do with SQL Server and FileStream.

    The Client-side filename function never gets called. It doesn't matter if you include the parens on the function name... Alpha removes them from the Client-side filename property.

    The issue is that it's a bug. There have been other recent bugs in Alpha regarding the Javascript functions in File Upload. This is just the next one.

    Report this to Alpha. Alpha should test each one of these properties... instead of piecemeal fixing one at a time as it's found.

    What bug in Javascript functions in File Upload are you referring to? Nothing has been reported to Alpha.
    For file download, the Genie suggests that you can set the client side filename with a Javascript expression. It appears that this is not implemented and the bug is in the genie. The help text should not have suggested that you can set the client-side filename at runtime using a Javascript function. We will look into what's involved in allowing the client side filename to be set dynamically at runtime or we will fix the help text in the genie.

  15. #15
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,279

    Default Re: getting Client-side filename function to work

    we have made a change so that in the next release the ability to set the client-side filename dynamically (by calling a JS function) is now supported

  16. #16
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,491

    Default Re: getting Client-side filename function to work

    Edgar, if you'd still like this action to work for you... in the way it was intended... then there is a fix you can employ for your build 5028. One of the great things about Alpha is the ability to get around issues like this. You can turn your Action Javascript into code. Sometimes you can then manipulate that code a bit to fix issues like this. Once you turn your Action into Code... you cannot go back to the Action... this is a one way change. So, make sure your Action is set up the way you want it.

    Make a copy of your UX.
    Get into your Action and select the "Text mode" radio button. You'll get a warning, and the Action will be turned into code. Once in code, you'll see 4 tabs at the bottom of the dialog. These are the 2 tabs we'll be using...

    Code:
    Declarations - Global
    Xbasic Functions
    Your Declarations - Global tab will have code like this...

    Code:
    {dialog.object}._functions.BUTTON_10_ACTIONBUTTON_1 = function() {
    
    var data = '__xbfunction=FileDownload_2f39c39661f24522a138a2161e9f1964';
    {dialog.Object}.ajaxCallback('','','__a5DownLoadObjectField','',data);
    
    }
    The code will include a guid after "FileDownload". Make sure you do not change your guid. Just work these changes into your code.
    Change the code to look like this...

    Code:
    {dialog.object}._functions.BUTTON_10_ACTIONBUTTON_1 = function() {
    
    var csfn = getFileName();
    
    var data = '__xbfunction=FileDownload_2f39c39661f24522a138a2161e9f1964&clientsidefilename=' +csfn;
    {dialog.Object}.ajaxCallback('','','__a5DownLoadObjectField','',data);
    
    
    }
    Here, a variable is created to get the client side filename from your client side filename function. Then, that variable is passed into XBasic code as a request variable.

    Next... in the tab Xbasic Functions... there will be XBasic code to set up a "p" dot variable with the options that were set in the Genie. There is one line that reads...

    Code:
    DIM p.clientSideFilename as C = "function:getFileName"
    Change this line to read...

    Code:
    DIM p.clientSideFilename as C = Request.Variables.clientsidefilename
    Here, we are setting the clientSideFilename option to the value of that Request Variable passed into this XBasic function.

    I've tested this under 5028 and it works nicely.

    Why Alpha would not give this to you as a potential solution I don't know. The Declarations - Global section is all Alpha code... taken from today's pre-release build.
    The only thing I added was in the XBasic Function tab to get that client side filename and assign it.

    When I read that this bug had been fixed and was in today's pre-release build, I'd hoped it would lead to a fix for your build... and it did.

Similar Threads

  1. Action Javascript File Download setting Client side filename
    By nkylelarsen in forum Mobile & Browser Applications
    Replies: 1
    Last Post: 03-27-2019, 12:16 PM
  2. File Download-How to set the client-side filename for embedded object?
    By nlk10010 in forum Mobile & Browser Applications
    Replies: 0
    Last Post: 03-10-2016, 04:16 PM
  3. Dynamic Client-Side FileName in Export to Excel Action Javascript
    By Progytech in forum Mobile & Browser Applications
    Replies: 5
    Last Post: 05-21-2014, 08:59 AM
  4. Client-side filename not being used in file download feature pack for embedded files
    By iviowa in forum Application Server Version 11 - Web/Browser Applications
    Replies: 4
    Last Post: 03-15-2013, 09:40 AM
  5. Client-Side Xbasic Function not work in a5v11
    By compee in forum Application Server Version 11 - Web/Browser Applications
    Replies: 2
    Last Post: 12-27-2012, 03:32 PM

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
  •