OK, this is a little complex but I will try and explain it as clearly as possible.
I have created a custom form, that writes the majority of the form data to the main list. Let's call it MainList for simplicity sake. However, within this form there is a section where people can add and remove components---there are 4 of them, and each one of these has the possibility to be a many to one type of relationship to the Main List(things like contacts, accounts, etc). So for instance, there might be 5 separate accounts that need to be associated with one MainList ID. As such, I have created a separate list for each of these, and use the MainList ID as a lookup in them.
This is working fine for creating new items and also getting back items from SharePoint to populate the form with data. However, this is where it gets tricky and where I need some help. People have the ability to go back in and edit this information at a later date. So let's say they pull the data from the MainList and then it takes the MainList ID and brings back all the associated data from the other 4 lists. Let's use Accounts as an example and take the 5 accounts as in the prior example. Well, they realize they forgot to add an account or two on there so they then add 2 more accounts. Or they realize they added an account that shouldn't be there and have to delete it. This brings up a problem or at least makes it much more complex now.
There are two approaches I can think of here:
1) When the file is getting submitted, delete the original record and its associated lookups from the lists and rewrite a brand new record. The issue with that is what if the re-write fails for whatever reason and now that record no longer exists at all in the list itself. This would appear to be the easiest way to do it, but also the riskiest and have the greatest chance for a big problem.
2) I bring back the list Id's from the GET call for the 4 many to one lists and store them in a hidden column in ui-grid, so I have access to check to see if that Id exists already. If it does, I can update it, if not insert it. Now to delete I would have to do the opposite. I'd have to check if there is a record in the list that already exists but I don't have the list Id in the hidden ui-grid column. This would mean they have deleted that record from the grid itself(I have add/delete buttons on the grid). I then would go in and delete the items that are no longer in the ui-grid but are in the list. In some instances it will be all three together...they will update some, delete others and create new ones.
This has the potential to be kind of messy and I wanted to see if there is a better way...as in, SharePoint will check the List if it is there and update it, and if not create it automatically without me having to do all this other code. I doubt it would have the delete if it's not there anymore built in, but I am hoping it might have the update/create dual functionality.
So the question I ask is what is the best way to handle these situations? I DO NOT have access to SharePoint Designer or it's workflows as this is a corporate site and those are not allowed. We do, however have access to use Nintex Workflows it appears. I would prefer a straight REST API solution if possible as I have not really delved into any workflow related stuff as of yet.
Any help would be greatly appreciated, I hope I described this in enough detail so it is clear what the issue is and what I need to do.