SharePoint User Group UK

Share the knowledge!

Welcome to SharePoint User Group UK Sign in | Join | Help
in
Home Blogs Forums Photos Files Roller

Checking SPListItem lock/Update status in code.

Last post 09-13-2007, 4:58 PM by Colin Byrne. 4 replies.
Sort Posts: Previous Next
  •  09-12-2007, 9:18 AM 5447

    Checking SPListItem lock/Update status in code.

    I have a slight problem with a WorkFlow that starts on creation of a new item. The item is created using a third party plug-in to move a Document from one library to another. The plug-in copies the document and then set's the fields accordingly.

    The problem I have is that my WorkFlow tries to update one of the fields being mapped during the activation sequence. I've moved the update into a second code activity after onWorkFlowActivated, but it still hits the same SPException.

    I'm not sure if this is because the item is still 'Locked' by the data copy process, or if it's just the fact that the item has been modified since the WorkFlow kicked off. Either way, I've tried to use item.SystemUpdate() to burn through the lock, but the exception below still fires. I've also tried putting the Thread to sleep for a minute, which makes me think this isn't a lock isue, but the fact that the item has changed.

    Message="The file 2TechnicalReview/SO1000305V1.XLS has been modified by Username on 12 Sep 2007 09:11:00 +0100"

    This only happens if I've used the data copy which updates fields, Manual kick off and upload work perfectly.

    Paul.


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  09-12-2007, 9:24 AM 5448 in reply to 5447

    Re: Checking SPListItem lock/Update status in code.

    Ok, the SDK confirms that this exception is thrown when other code has updated the SPListItem object. Is my only solution here to delay the creation of the item object in memory, or at least check if it's the most valid version and if not, to re-create it?
    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  09-12-2007, 12:26 PM 5459 in reply to 5448

    Re: Checking SPListItem lock/Update status in code.

    Ok, well a 30 second delay in a code activity placed before the OnWorkFlowActivated activity hasn't stopped this problem. Does this mean that the workflowProperties becomes out of date if someone edits the item manually?

     


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  09-12-2007, 1:46 PM 5464 in reply to 5459

    Re: Checking SPListItem lock/Update status in code.

    This time I've stuck a 5 minute delay activity between onWorkflowActivated and the next activity. I'm guessing that by dehydrating and rehydrating the item, this updates the data..

    This strikes me as a really messy way of doing this which while it works, is going to give me problems in the long run. For now it's going to get my pilot off the ground, but I'll welcome anyone's suggestions in this..


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  09-13-2007, 4:58 PM 5494 in reply to 5464

    Re: Checking SPListItem lock/Update status in code.

    Hi,

    To avoid this issue I'd probably hook the OnItemAdded event on the doc lib in question and start the workflow manually after doing a Thread.Sleep for 60 seconds. This would mean all the metadata is ready for when the WF kicks off.

    Now if you could control the code for the copy you can add files and set the metadata in one go via the object model in which case you wouldn't need the workaround.

    Colin.

     

     

     

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems