Discussions

Expand all | Collapse all

Want a link / button to download a file after creating log using API_AddRecord

  • 1.  Want a link / button to download a file after creating log using API_AddRecord

    Posted 01-13-2018 06:11
    I am struggling with the code to create a link that allows a user to download a file attachment, but at the same time creates a log to identify the user and the time of download.

    The code I have is below and it successfully creates the log record, but does not download the file.

    If ([Original File]>"", "<a href=\"" &URLRoot() & "db/" & [_DBID_ACCESS_LOGS] & "?act=API_AddRecord" & "&_fid_6=" & ToText([Record ID#]) & "&ticket=auth_ticket" & "apptoken=app_token" & "up/" & "db/" & Dbid() & "/a/r" & [Record ID#]& "/e7/v0\"target=_blank\">" & [Original File]& "</a>" ,"")

    Any help in identifying where I am going wrong would be appreciated.


  • 2.  RE: Want a link / button to download a file after creating log using API_AddRecord

    Posted 01-13-2018 14:20
    Let�s start simple.

    Try making formula URL field, not a formula Rich Text field

    var text URLONE = URLRoot() & "db/" & [_DBID_ACCESS_LOGS] & "?act=API_AddRecord" & "&_fid_6=" & ToText([Record ID#]));

    var text URLTWO = URLRoot() & "up/" & Dbid() & "/a/r" & [Record ID#]& "/e7/v0\";

    // be sure to set the 7 in e7 above to be the field Id Number if the field that is the file attachment

    $URLONE
    & "&rdr=" & UREncode ($URLTWO)

    I put an app in the Exchange that explains this syntax. It is called URL formulas for Dummies. Search on Dummies and you should get a hit.

    If you get this working and want to be able to control the appearance if the button and have it be a link with the file name, let's tackle that one after the easier version is working.
    Let me know how it goes and if you get any syntax errors please post you formula and the error.


  • 3.  RE: Want a link / button to download a file after creating log using API_AddRecord

    Posted 01-14-2018 01:19
    Thanks very much for this but I am still having problems 

    Problem 1
    When I put you code into the field I get a Formula syntax error

    The argument list of the function rdr must begin with a left parenthesis.


    var text URLONE = URLRoot() & "db/" & [_DBID_ACCESS_LOGS] & "?act=API_AddRecord" & "&_fid_6=" & ToText([Record ID#]);

    var text URLTWO = URLRoot() & "up/" & Dbid() & "/a/r" & [Record ID#]& "/e7/v0\"; 

    $URLONE 
    & "&rdr  =" & URLEncode($URLTWO) 

    Problem 2
    When I deconstruct your code and put it into a URL I still get delivered the xml response and it does not go on to download the actual file.

    This is the key thing I am trying to achieve i.e. first create the log (which the first URL does successfully) and THEN download the file.


  • 4.  RE: Want a link / button to download a file after creating log using API_AddRecord

    Posted 01-14-2018 01:42
    Can you change this part of the code to this? Get rid of that backslash

    & "/e7/v0";


  • 5.  RE: Want a link / button to download a file after creating log using API_AddRecord

    Posted 01-14-2018 08:23
    Worked perfectly - thank you very much


  • 6.  RE: Want a link / button to download a file after creating log using API_AddRecord

    Posted 01-14-2018 13:43
    Great, thx for letting me know.