I would like to have an interface that, when it is accessed/loaded/refreshed by user, will write a row to a table in the database.
Is this possible?
Idea: Perhaps by using a!writeToDataStoreEntity, or a!startProcess? But it seems that these do not work outside of a "button click" by the user. Trying to add it outside of a button is giving me errors like this one:
Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error : Cannot create context for UI expression. Reason: A value of type "Reaction Tree" was stored in the variable "write", but values of this type cannot be stored in SAIL context variables. Use a with() variable or change the type of this value.
Thank you in advance for any ideas or advice!
Discussion posts and replies are publicly visible
Dear Jim and Raghavendra, Thank you very much for your inputs! Thanks to your input, I was able to accomplish this using a workaround making use of some of the suggestions mentioned. While, as Jim mentioned, it is not possible to use POST requests without user trigger/click, I was able to find a workaround by making a GET request to a custom Google Apps Script (external web service), then using that to add the row to a DB (it acts as a POST request). I ended up writing to an external DB instead (but if I needed to write to an internal DB, I would have called the Web API from Google Apps Script to write back to Appian, as Raghavendra suggested). The code in the UI looks like this: load( local!temp: a!httpQuery( url: urlwithparameters("script.google.com/.../exec", {[parameter names here]}, {[parameter values here]}) ), {} )
For anyone trying to accomplish this, the Google Apps Script code is quite simple; basically is using the doGet method detailed here:
developers.google.com/.../web
Thank you again, Jim and Raghavendra! Agustin
Has anyone come up with a solution for writing to a database on a UI load without any external development, so purely within Appian?
I'd be more interested in what the actual use case is. At my current client they want an audit log entry written each time someone navigates to a Record Summary and/or any other Record related View. The instinct is to try and achieve what's described above but in actual fact Appian does write to an audit log these events (look in system logs/audit/records_usage.csv). This contains all the relevant details for these events and it then becomes a matter of extracting those events and dispatching/storing them as required.
Hi Stewart, so the Use Case is exactly the same apart from the key question - WHO accessed the record. I have reviewed the log files and while it tells you what record has been accessed, I dont think it tells you what instance of the record and who accessed it.
I hear you - this gave me trouble as well, and I don't know of a solution to both parts of your problem (1 - who, 2 - which record).I want to give an update that when I was trying to do this, I was trying to track the user as well and I later found the logs, as Stewart commented. Since I was using Sites, I was able to do what I needed to with /audit/sites_usage.csv .
For the user (the "who" part of the question), you will see the user UUID in the log Stewart mentioned, which looks like: _h-0000aa15-eaaa-9000-9aa-010a02084a_3I got a list of all usernames, then used the user function on those to build a mapping table between usernames and UUIDs like user(X, "UUID").You can also search by UUID under "/suite/design" - USERS - Search box.
-Agustin
Dai Williams - You can create a process to insert the data before the form loads...