Need to update audit in table while clicking a!safelink

Certified Senior Developer

We are using a!safelink to provide provision to download a file using presigned URL. The requirement is we need to store which user clicked on the link and when in audit table, but

as in the safelink there are no saveinto parameter . I tried multiple other ways but all in vain.

I am unable to find a solution, where on a single click user able to navigate using presigned url as well as in backed it writes to audit.

 please advise what to do that in this case and any work around we can do to achieve the requirement.

Thank you in advance

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    It is not possible to download and write to audit in single click. You can however have a process with start form. User can click on the download link in the start form and close the form using submit button. In process you can use pp!initiator to write the data in audit. 

  • 0
    Certified Lead Developer

    Since a!safeLink doesn't support saveInto, we implement a two-step download process - first click logs the audit, second click downloads the file.

    Have a look at sample code for your reference:

    a!localVariables(
      /* Track whether the initial link has been clicked */
      local!linkClicked: false,
      local!presignedUrl: "www.google.com",
      {
        a!linkField(
          links: {
            /* STEP 1: Initial link that triggers audit logging */
            a!dynamicLink(
              label: "Click to Download",
              value: true,
              saveInto: {
                /* Set flag to show the actual download link */
                local!linkClicked,
                /* Write audit record using a!writeRecords */
                /*a!writeRecords(records: {}, onSuccess: {}, onError: {})*/
              },
              showWhen: not(local!linkClicked)
            ),
            /* STEP 2: Actual download link shown after audit is logged */
            a!safeLink(
              label: "Download Now",
              uri: local!presignedUrl,
              /* Only show after the first link is clicked and audit is logged */
              showWhen: local!linkClicked,
              openLinkIn: "NEW_TAB"
            )
          }
        )
      }
    )

  • 0
    Certified Senior Developer

    Thanks    for your response. But since solution I wanted is with single click and I have already implemented this with two clicks. Will look forward for Appian to introduce this feature since this is a valid Use case.

  • +1
    Certified Lead Developer

    This is how SafeLink works, and has always worked.

    The best supported solution will simply involve 2 user clicks, in a large variety of possibilities. One click will persist whatever data you want to the DB, and the other click will be the user opening their link.  I would suggest that you require the user to first click a button (for instance) to "generate link" or "show link" where it both un-hides the existing link but then also persists your log data (and anything else you like).

  • 0
    Certified Lead Developer
    in reply to Anvesh Shetty
    Will look forward for Appian to introduce this feature

    Honestly I'm not sure how technologically feasible it is - just due to the nature of how standard web-links work.  As far as I can tell they might be stuck completely separating (functionally) links that actually open a web link, from other styles of link that intiate any sort of interface-side and/or appian-side data processing, etc.

  • 0
    Certified Lead Developer
    in reply to Anvesh Shetty

     Technically, achieving this with a single click is difficult now and, as per my understanding, it will remain so in the future. Currently, every application in Appian follows the approach I mentioned, which is highly recommended. This method ensures the user experiences it as a seamless process rather than feeling like two separate clicks.

  • 0
    Certified Lead Developer
    in reply to Shubham Aware
    as per my understanding, it will remain so in the future

    Agreed - Appian most likely has overriding factors preventing them from doing this even if it were technically possible to hack it in - things like web security or data safety or other things we as devs might find kinda arbitrary when faced with a use case that would even be 10x easier if only they'd cram the feature in.  Meanwhile there are lists of dozens of feature completeness and QoL updates they could EASILY add, with MINIMAL code refactoring or bespoke code required, that STILL get consistently overlooked ("we just don't have time, we're too busy implementing new stuff nobody is asking for..." Confounded), so I wouldn't count on anything like this getting approved and out of their backlog anytime soon...

  • 0
    Certified Lead Developer
    in reply to Mike Schmitt

    Yeah, makes sense - seems like a limitation we’ll have to work around for now. Hopefully Appian prioritizes more practical QoL features in the future.
    Thinking of setting up a public community portal where devs can post and vote on must-have Appian features might be a good way to show Appian what improvements matter the most to us.

  • 0
    Certified Lead Developer
    in reply to Shubham Aware
    Thinking of setting up a public community portal where devs can post and vote on must-have Appian features

    Funny, because I was just saying the other day in the Discord how I was thinking about setting up a place where devs can place monetary bounties on the features they most want, to be paid to the Appian Engineer responsible for getting such feature into general release.  Sadly I'm not sure if I have the time or pre-built platform for such a thing if it were to be robust and user-friendly enough for general use.

  • 0
    Certified Lead Developer
    in reply to Mike Schmitt

    An issue with this design is that user details will be added to log even before they downloaded! If user generates the link but doesn’t download then log has an invalid/inaccurate entry. Writing to logs after download is more integral though might need additional click as suggested in my earlier response!