Simple update into a database using the Query Database smart service

Dear all,

I would like to make a quick update to just one database column and trying to use the Write to Database smart service, I am required to populate all the other fields.  Because I do not need to start getting all the other fields just so I can update on field, I am trying to use the Query Database smart service instead.

I have the following simple database update query:

UPDATE cshvcashadvancedata SET currentstatus = "Manager Rework -test has worked" WHERE id = ac!requestId

In the setup tab, I defined the above query.

In the data input tab, I added an ac (see screenshot below).  However, the database update is not getting performed. I also noticed that Appian automatically added a new input node - ~1.requestId (I'm not sure what that is for).

Is there anything I am missing?

Thanks

 

  Discussion posts and replies are publicly visible

Parents
  • Hi Susan,

    As other suggested, please follow the below steps

    (1) Use Write to Data Store Entity Smart Service instead of Query Database.


    (2) To update specific columns, please create a CDT and specify the <xsd:element> for those columns (not all). While creating this CDT, the primary key should not have anotation @GeneratedValue. 

    (3) Use this CDT in the Smart Service and map the columns values to the respective ac!variable. Also, map the primary key value. So the compiler will know that this is an update not an insert.

    Hope this helps!!!

    Thanks,
    Farnaz

  • 0
    A Score Level 1
    in reply to Farnaz
    Thank you guys so much for your kind guides.

    I will go ahead and use the Write to Data Store Entity Smart Service. However, I am do not believe I've understand your instructions as to how to include my WHERE (using SQL thinking). For example, I have a table as follows:

    Table_Requests
    -----------------------
    id - int, autoincrement , primary key
    amount - decimal
    requestDate - datetime
    employee - text

    Supposing I want to update a specific row where id is equal to 30 (WHERE id = 30) with values {amount: 2345, requestDate: now(), employee: logginuser()}

    I can set this up in the input node of the Write to Data Store Entity Smart Service. BUT I cannot see were to set the id to pv!currentRequest (I already have a process variable with the value of the id WHERE or which row to update).

    If someone knows how to set the condition for the row to update in the input or output node of the Write to Data Store Smart Service, please can you show me using a screenshot when you have the chance?

    Thanks
  • 0
    A Score Level 2
    in reply to susana197
    Hi Susan,

    While updating a column in DB, you need the Where Clause.

    The same need not be replicated in Appian Concept.

    If the pv!currentRequest .id =30, and the rest of the columns hold the appropriate value, this implies that the row where id = 30 should be updated, no need to specify the where clause.

    Hope this answers your query!!

    Thanks,
    Farnaz
Reply Children
No Data