Write a row to DB on UI load?

Certified Lead Developer

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

Parents
  • Hi Agustin,

    Did you try this with Web API and configure it in integration and call it as a rule in the UI?
  • 0
    Certified Lead Developer
    in reply to Shanmukha
    Dear Raghavendra,

    Thank you for your smart suggestion! I am trying to do this - I setup a Web API that successfully writes to the DB; then I setup an integration that calls the Web API (this works too, and causes the successful write to the DB). Now, I am calling the integration as a rule from the UI as follows: load( local!test: rule!testIntegration(onSuccess: null, onError: null) , {} ) - however, this fails with a similar error about "Reaction Tree" as the one above. Do you know if I am calling it incorrectly from the UI?
  • +1
    A Score Level 1
    in reply to agustinc
    Hi Agustin,

    Sorry for the delayed response. If it not working then we must use the tradition SOAP based web service calling from the UI. This should defiantly work.

    I hope it may help you.
  • +1
    Certified Lead Developer
    in reply to Shanmukha
    You're not going to be able to call an a!httpWrite() or an integration rule that POSTs data from a load(), those have to be bound to buttons/links with bind() or called from a saveInto(). User action is required to trigger something like this.
  • +1
    Certified Lead Developer
    in reply to jims419

    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

Reply
  • +1
    Certified Lead Developer
    in reply to jims419

    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

Children
No Data