Find a list item and update it

Nov 24, 2011 at 4:32 PM

I'm a little new to this whole JQuery/SPServices thing, I've used some copy/paste with small modifications but I've run into a wall.
I'm trying to work around a limitation, I don't have, and can't have, SharePoint designer. Otherwise, this would probably be a workflow.

What I'm trying to do is when a new list item is created in List A, I want to look for an entry in List B that matches two columns and update it if it exists or create a new entry in List B if it does not.

I'm trying to work myself up to coding this, and just wanted to make sure I'm headed down the right path.
My current thoughts are to use a GetListItems call to List B,  Use the fitler node(I'm not sure about this part), and then pass the results to an UpdateListItems for List B, this action will take place on the submit of a newform in List A.

Any pointers would be helpful, or a link to someone who has already done this would be awesome. I'm going to try building it this weekend.

 

Coordinator
Nov 24, 2011 at 5:14 PM

cstone:

You've got the right basic ideas. For the filtering, you'll want to use the CAMLquery option and pass the right CAML in so that you only get the matching items in list B back (or none). Then your logic will branch to either add a new item to list B or update the existing item.

As for the triggering, you can use the PreSaveAction in list A. The trick will be to only write to list B when the user is really done. For instance, if there is a validation error, the page will reload. The first time you would create the item in list B, and the second time you would update it. However, if the user changes one of the two fields that you are using to match on, you might end up with orphans. Those edge conditions will be the tricky bits.

M.