what is the best way to handle preventing two user...
# ask-stanley-ai
m
what is the best way to handle preventing two users from editing the same record simultaneously and causing the "record has been changed" error?
c
AI generated answer (using internal Slack threads):
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** To prevent two users from editing the same record simultaneously and causing the "record has been changed" error, you can consider the following approaches: 1. Locking the Record: You can create a workflow that locks the record when it is being edited. This can be done using a Before Load User Event script that runs on edit to lock the record for other users. However, this approach might lock the record for everyone, not just the other users trying to edit it. 2. Using Last Modified Date: You can use the 'lastmodifieddate' field to check when the record was last updated. This can be done using the
nlapiLookupField(nlapiGetRecordType(), nlapiGetRecordId(), 'lastmodifieddate')
function. This field gets updated upon submission of the record. However, this approach might not work if the second attempt to access the record happens before the first record submit actually completes. 3. Using Websockets: If you have somewhere to host a script, you can potentially use websockets to handle real-time data changes and notify users accordingly. 4. Custom Tool: You can also consider creating a custom tool that handles this scenario. This might involve more complex scripting and might be a bit hacky, but it could provide a more tailored solution to your specific needs. Remember, these are just potential solutions and might not work perfectly in all scenarios. You might need to experiment with different approaches and see what works best for your specific use case.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.823127687
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.816370904
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.815454
Please provide your feedback on this answer.
a
There's also (for custom record types only, AFAIK) the option of disabling optimistic locking, but I haven't tested this to see if it does what you want.
m
I would have to double check, but the issue we had with optimistic locking was that if the later record save had blank fields, those would overwrite and remove any fields added by another user. I appreciate the suggestion, though!
a
That's an important point. Now that you mention it, that does the OPPOSITE of what you're asking.
👍 1