Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top