I have a few places where it would be really nice to have a method that fires when a record is changed and make some changes to another record.
Examples include a UD table we use to store hospitalization information for employees and their dependents. (If I make the employee record inactive, would like to do this to all dependents for that employee) I’ve also tried to create something where revs to a parent part would cascade to child parts. The issues I have is no matter what method I try, I seem to always get the “Row has been modified by another user” error.
I’m assuming there has to be someway to do this and I’m just coming at it wrong, so is there a best way to approach something like this or is it simply not possible? Any help is greatly appreciated.
Todd, you should be able to make these changes as you wish- if you are getting that error it could be due to many things (incorrect customization being one of them).
However, you may be coding just fine, it could be that there are other BPMs/Data directives that are causing the “Row has been modified by another user.”
Do you have any other BPMs or data directives on the UD table you are trying to modify?
I would try to turn those off as you are developing to see if what you are doing IS working properly and that it may just be the other code that is causing it to fail.
The only other method on this UD table is on the GetANewUD22 which uses a sequential counter to provide the key.
And this is the method I’m trying to use for updating:
The Show messages are temporary to see whether it is running through the method. (It is)
The conditional checks that the field has been changed.
I set two variables to match those in the ttUD table row.
The query is pulling all records that match the variables and supposed to leave all fields the same except the one checkbox I am trying to change.
I am running this method on Pre-Processing on Update and trying to update the ttUD22 table so that it then updates the UD22 table.
As a general rule, I do updates to other tables in Post Processing, it always seems to work better there. The error about record has been changed doesn’t happen often in Post Processing. I can’t explain WHY this is, I just know from experience that it works that way. I’ll make note (a flag of some sort, usually in callContextBpmData) that something needs to be done, then do the work in Post Processing.
Just my 2 cents
It would help to see the code and at which point you are getting the error.
It happens because the sysrevid value in the db is different from whatever you are sending, meaning your changes are not on top of the most recent version, so someone else made changes.
It could be happening within your process, or something you are changing is triggering other changes so you need to refresh before keep making changes. Hard to tell what exactly without more details.
I’m not using any code at this moment. Simply using the objects available.
The changes I am making are changing Checkbox01 to true and setting Date02 to today. I’m doing this using the objects though and not using any code to do it.
I’ll try this and see if it makes a difference.
Todd, do you have any other BPMs or Data directives hooked up to that table? Or is this the only one?
So you are using the UD22 BO, and putting a preprocess BPM on Update.
You are modifying fields in the ttUD22 table and you get the “record modified by another user”?
Can you try simplifying the BPM? just get the record and set a value, see what happens.
What is fill by table doing?
The fill table uses the query to pull all the records from UD22 that have the same EmpID and ItemCode as the record that is being changed. It then uses those records to fill ttUD22 with all the same info except Checkbox01 value is set to true and Date02 is set to today’s date.
As far as simplifying it, I’m not sure what I could simplify. I can set a field on the current record that is being changed. That works every time. My issue is trying to set a field on a different record than the one being currently changed. I want to look at what record is being changed and adjust a different related record to have the same value. Is there some other way to go about it that I’m missing? It’s completely possible that fill table is wrong. I’ve also tried Update Table by Query. I’m not adverse to using a code block either, just looking for the simplest way to accomplish the task.
I don’t know if adding records to the temp table in the preprocess bpm will work, I think it is best to do it in a post process as someone else mentioned before.
After the current record is updated, get all matching records from the db, update and save them.
I ended up using a preprocessing to set the info I needed into BPM Context variables and then used a post processing to fill a table and use the UpdateExt method to update.