Hi,
I am trying to use a!writeRecord function in an interface button save into block. Below is my code. Id is a Primary Key and is set as AUTO_INCREMENT in the database table. When I set the id as 0, it doesn't seem to accept the identifier and hence fails. What should I do in order to write a new entry into the table using this function?
PS : I am able to update the record and the corresponding row in the DB with an existing identifier.
Discussion posts and replies are publicly visible
Leave the id empty or null.
I tried setting id as null or "", it still doesn't work. I tried commenting out the id line all together but no luck.
If it really is an auto-increment primary key, you don't need to include the id field at all. Also, is this an action on a button? docs.appian.com/.../executing_smart_services.html
That was my initial assumption too. If I include id field with null/empty/0 or exclude it altogether, it doesn't work either way. Yes, it is called on a button action i.e. inside saveInto()
Did you setup the DB table yourself or using the wizard in the record?
I used the record wizard to configure the source table (sync is enabled).
I am having similar issue, and tried without id, with null or "" id...not working.
Please let me know if you fixed it somehow..
I did a quick test and had the same issue. Writing a new item, fv!recordsUpdated was empty. But in the DB I had a new row with the correct values. Then I checked my record for applied source filters ... and BINGO. The item I added to the DB did not get pass that filter. I removed that filter and a retest showed that fv!recordsUpdated is not populated as expected.
I think this is expected, while somewhat tricky to debug when you do not have that source filter in mind.
How do we handle when i have few rows to update and few new records...
I have a usecase where user want to edit as well as add new rows. I am not able to use a!foreach and i am not able to use if() to check if id exists or not exists.
When i use if() condition, this is how data looks, getting saved to same record either new or existing.
If i apply a!foreach() i am getting pink box.
Is there a specific way of doing this...
You cannot call more than one smart service function like a!writeRecords in a saveInto.
I do not really understand what you try to do with all that code in your screenshots. Why all these copy actions from local to a new record?
You can write almost any number of records of the same type in one go. The ones with a valid primary key value will be updated, any other will be inserted. I suggest to read the documentation to understand in more detail how this works.