Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Ok, here's the scoop. I have bunch of lists on sub sites that I am rolling up into a list on the parent site. Here is what I have for code:

                            var title = $(this).attr("ows_Title");
                            $().SPServices({
                                operation: "UpdateListItems",
                                webURL: "/",
                                async: false,
                                batchCmd: "New",
                                listName: "Initiatives",
                                valuepairs: [["Title", title]],
                                completefunc: function(xData,status){
                                    alert(xData.responseText);
                                }
                            });

Problem is that when I execute this script, it always adds a new item, even if the name exists. I tried switching batchCmd to "update" but then if the item doesn't exist it won't add it to the list. Is there something built into SPServices that I could use or do I need to roll my own check?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You have to "roll your own check". User GetListItems to see if there is an existing item and then conditionally either add a new item or update the existing one.

share|improve this answer
    
Thanks Marc, I just threw the titles in an array and then checked the current title to the ones loaded. Thanks Again –  Brenton Pierce May 30 '12 at 15:53

You have to roll your own, there isn't anything built in. The closest is a form operation, SPRequireUnique. You'd need to do a GetListItems operation to first see what's in the list, compare it to what you have and either skip it, update it, or add it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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