2

We got code, running on page load. That code asks certain SPList for its items by CamlQuery, which gets only items with specific (current) user in one field (field A) and with some value in other field (field B). Combination of those two field makes items unique.

So when there is no such item, we create new one.
If there is such item, we only update it.

So we dont want to have duplicate items with same values in fields A and B. And code which I described, works pretty well.
With one little exception - when user have more than one home page set on our SharePoint in his browser, every loading homepage executes this code at the same time. That means GetItems with caml query returns no item in both cases, so both requests creates same new item.

Questions are: Can we avoid this? How? Are there any logical errors in how we manipulate with items?

0

1 Answer 1

1

As long as you don't have a SharePoint farm with multiple WFE servers, you should be able to solve this problem by enclosing the critical code section in a lock statement.

Related questions from StackOverflow:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.