Question on querying database

Hi to everyone,

suppose to have a database table called APAC_REQUEST_MANAGER made in this way:

USERNAME REQUESTOR_NAME REQUESTOR_SURNAME COUNTRY
Clerian001 Andrea Clerici Cn
casalal001 Andrea Casalucci Cn
cattagi001 Giuseppe Cattaneo Cn
cattagi001 Giuseppe Cattaneo Jp
cuvama Marco Cuva Jp

I've created a sail form with two different dropdown field:
.Country, with value determinated by a query rule on this table
.Requestor, where i want to use a query rule that, depending on the country selected on the previous form, will make a query on the database and will have as choice Label the REQUESTOR_NAME + REQUESTOR_SURNAME ordered in an alphabetical way an...

OriginalPostID-200799

OriginalPostID-200799

  Discussion posts and replies are publicly visible

  • ...d as choice Values the corresponding USERNAME.

    Before Sail i will use a query database node with this query SELECT DISTINCT USERNAME, REQUESTOR_NAME || ' ' || REQUESTOR SURNAME FROM APAC_REQUEST_MANAGER WHERE COUNTRY=ac!country ORDER BY REQUESTPR_NAME || ' ' || REQUESTOR_SURNAME, i will save the result on the multiple text pv!username and pv!requestorNameSurname.

    My question is if there is a way to use one ore more query rule that replicate this result so that i can use it on the form and the value of the second dropdown will be dinamical?
  • @marcoc I believe a database view which concatenates the requestor's name and surname might be a cleaner way of doing the same. Also attached a code snippet of how you can do the same without making use of a database view.

    Let's see what other practitioners opine and do let us know if you have follow up questions.
  • There are couple of approaches I can suggest here,
    1. Best approach would be to add one more column into DB to have full name. That will be the best approach to handle this situation with less overhead at Appian end.
    2. Another approach as below,
    You can handle this at Appian end also as per the attached code. Here, you need to make a call to use which approach as this may affect performance if the number of users are large.
    Still let me know if this works.

    Main Rule - Dropdown.txt

    TEST_formUserData.txt

  • You can have the database concatenate fields together to make a readable name using a select statement or a view. The select statement is easy but only useful if you are using the SQL smart service. For a view, it works great, but the downside is that you can't update data in a view directly by writing to the datastore (using the mapped CDT to the view). One solution would be to add a generated column to the actual database table. The generated column could functionally concatenate the 2-3 name fields (first, last, middle, etc.) that you have in the same table. You would then use the table like you normally do, mapping a CDT to it and query entities, etc. As long as you don't attempt to update the generated column in your CDT directly I assume this will work. When you write the updated CDT (with first & last name changed, or other random columns) to the datastore and retrieve the current version the generated column would be correct.

    1) I haven't tried a generated column in years, let alone in Appian, so there may be a gotcha
    2) If you allow a user to change the constituent values in the CDT that you use to generate the extra name column, it is possible that until you write & retrieve the updated version from the DB, the users may see the 'old' generated value. i.e. Changing firstname='john' to 'Beth' and lastname from 'doe' to 'Something random' would mean your full name would still show as 'john doe' instead of 'Beth Something random'...until you write & retrieve the updated data.