995
Views
13
Comments
How do I update entity data with the Update server action?
Application Type
Traditional Web

I'm trying to set up my bootstrap so that it updates the entity if it's not empty, and creates the entity if it is. I added the update action in the false flow, and the action says that it replaces all the attributes in the entity record, but when I run this nothing happens. Am I using update incorrectly? Do I need to use a different action?


2020-09-21 11-35-56
Sachin Waghmare

Hi Joseph,

First, I would like to advise you to please try to debug the flow of this action and find where the control is going after List empty check? Also, it might be the case that you are not getting the list empty and it is going to true condition and not creating any new record since that set of records already exist, if there is any index setup on that entity.

If possible for you please share the OML with us to find the exact cause.

Thanks & Kind Regards,

Sachin

UserImage.jpg
Joseph Kuhn

Hi Sachin,

How exactly can I debug this? I have nothing in my UI to make this action go, so "start debugging" does nothing. I tried running the timer but nothing happened when I did. I'm not sure how else I can track if the flow is working properly or not. Also, what is the OML?

2020-09-21 11-35-56
Sachin Waghmare

It is the OutSystems Module file which can be saved as .OML file. 

Please go to the Menu Module --> Export --> Save AS and give it a name and attach here.

UserImage.jpg
Joseph Kuhn

I attached the file here, there are multiple entities that I want to do this with but they're all set up the same way so I only need help with one of them ie. TheLatestTrends

AwardsVoting.oml
2018-10-29 08-31-03
João Marques
 
MVP

Hi Joseph,


You need some kind of key to identify the record you want to update or if you want to create a new one.

Something like in this image, where you check first if it exists the record in the database (in the example, I'm checking by Nomination attribute). The CreateOrUpdate will create a new record if Id is null (doesn't exist already) and update if the id is not null (in the case it exists a Trend with that Nomination):


OML in attachment.


Hope it helps.


Regards,
João

AwardsVoting.oml
UserImage.jpg
Joseph Kuhn

So this should replace all of the entity data with whatever is in the excel file, right? I just tried to run it and the record that I wanted removed is still there. Can this action not handle deleting things as part of the update?

UserImage.jpg
Joseph Kuhn

Also, once I make a change in excel, is it necessary for me to re-import that excel file or will it update automatically?

2018-10-29 08-31-03
João Marques
 
MVP

Wait a second, you want to remove the data that is no longer in Excel file?

If that is the case, the easiest way is to delete all records in bulk with an Advanced Query and create it once again.

NOTE: Be careful when deleting data that might be referenced, so if you are using the LatestTrendId in another table, you might have database inconsistencies if you remove the record.

Regarding the second question, this logic flow is binded to a Timer which is scheduled to run When Published. So whenever you publish this module, this timer (and the logic flow associated to it) will run.

AwardsVoting.oml
UserImage.jpg
Joseph Kuhn

I apologize if I'm not being very clear. I want to update to exactly what is in the excel file; that is, if I delete a record, add a record, or change an existing record, I want the entity to update to that with each publish. Is all of this possible with just the CreateOrUpdate, or do I need the Delete in there as well?

2018-10-29 08-31-03
João Marques
 
MVP

Hi Joseph,


The above solution and OML will cope with your requirements.

It will delete everything and it will insert the new data, so:

  • what was there will still be there (it will be removed and inserted again in the database)
  • what is no longer there will be removed from the database
  • what is new, it will be inserted in the database
UserImage.jpg
Joseph Kuhn

The delete worked and cleared everything, but now for some reason the CreateOrUpdate is not adding the records to the entity and it's staying empty.

2020-09-21 11-35-56
Sachin Waghmare

Could you please confirm why you are using the Bootstrap action? Just to update the data into the entity? IF so, there is a already default entity action named as CreateorUpdate which can be used to update in case if record already exist or to insert the new record. Please refer the below link to get more details about BootStrap.

https://success.outsystems.com/Documentation/How-to_Guides/Data/How_to_update_a_Bootstrap_Action_to_fetch_an_entity_identifier_from_Excel

UserImage.jpg
Joseph Kuhn

I attempted to use CreateOrUpdate but it either didn't do anything or just created duplicate entries. I'm not sure why.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.