UpdateListItems - Won't create new items with same data

May 8, 2012 at 5:22 PM

I am using the UpdateListItems to create new items in a list.  When I try and add another item with the same data it does not work.  It acts as if the item is already there and does not create the new item.  If I delete the original item created and add again, it will add the item, but then when I try to add the same item again it does not add it.

 

Here is my function:

function CreateNewItem(CMDueDate, PMDueDate, PDDueDate, QADueDate, QCDueDate, ManagementDueDate, ReportedMonth) {

    var CMDueDate = formateDueDateToSP(CMDueDate);
    var PMDueDate = formateDueDateToSP(PMDueDate);
    var PDDueDate = formateDueDateToSP(PDDueDate);
    var QADueDate = formateDueDateToSP(QADueDate);
    var QCDueDate = formateDueDateToSP(QCDueDate);
    var ManagementDueDate = formateDueDateToSP(ManagementDueDate);
    var ReportedMonth = ReportedMonth;

    var querybidPackage = "<Query><Where><Contains><FieldRef Name='cdcrCurrentStatus'/><Value Type='Text'>Active</Value></Contains></Where></Query>";
    $j().SPServices({
        operation:"GetListItems",
        async:false,
        webURL:'/',
        listName:"Bid Packages",
        viewName:'26b2611c-b7a3-430c-8902-a74ca646bc36',
        CAMLQuery:querybidPackage,
        completefunc:function (xData, Status) {
            //alert(xData.responseXML.xml);
            $j(xData.responseXML).SPFilterNode("z:row").each(function () {
            
                var cdcrConstructionManager = $j(this).attr("ows_cdcrConstructionManager");
                var cdcrProgramManager = $j(this).attr("ows_cdcrProgramManager");
                var cdcrCDCRProjectDirector = $j(this).attr("ows_cdcrCDCRProjectDirector");
                var cdcrSiteDirectory = $j(this).attr("ows_cdcrSiteDirectory");
                var cdcrBidPackage = $j(this).attr("ows_ID") + ';#' + $j(this).attr("ows_Title");
                var title = $j(this).attr("ows_Title");
                var cdcrPhase = $j(this).attr("ows_cdcrPhase");
                var cdcrBidPackageURL = $j(this).attr("ows_cdcrBidPackageSite").split(',')[0];
                var cdcrMRTaskPage = $j(this).attr("ows_cdcrBidPackageSite").split(',')[0] + '/Pages/MR-Home.aspx, Monthly Report Task Page';
                
                if ( !cdcrConstructionManager ) { var cdcrConstructionManager = ''; }
                if ( !cdcrProgramManager ) { var cdcrProgramManager = ''; }
                if ( !cdcrCDCRProjectDirector ) { var cdcrCDCRProjectDirector = ''; }
                if ( !cdcrSiteDirectory ) { var cdcrSiteDirectory = ''; }
                if ( !cdcrBidPackage ) { var cdcrBidPackage = ''; }
                if ( !title ) { var title = ''; }
                if ( !cdcrPhase ) { var cdcrPhase = ''; }
                if ( !cdcrBidPackageURL ) { var cdcrBidPackageURL = ''; }
                if ( !cdcrMRTaskPage ) { var cdcrMRTaskPage = ''; }
                
                $j().SPServices({
                    operation:"UpdateListItems",
                    async:false,
                    batchCmd:"New",
                    listName:"Monthly Report Tasks",
                    valuepairs:[
                        ["Title", title],
                        ["cdcrCMDueDate", CMDueDate],
                        ["cdcrPMDueDate", PMDueDate],
                        ["cdcrPDDueDate", PDDueDate],
                        ["cdcrQADueDate", QADueDate],
                        ["cdcrQCDueDate", QCDueDate],
                        ["cdcrManagementDueDate", ManagementDueDate],
                        ["cdcrConstructionManager", cdcrConstructionManager],
                        ["cdcrProgramManager", cdcrProgramManager],
                        ["cdcrCDCRProjectDirector", cdcrCDCRProjectDirector],
                        ["cdcrSiteDirectory", cdcrSiteDirectory],
                        ["cdcrBidPackage", cdcrBidPackage],
                        ["cdcrBidPackageURL", cdcrBidPackageURL],
                        ["cdcrReportedMonthly", ReportedMonth],
                        ["cdcrMRTaskPage", cdcrMRTaskPage],
                        ["cdcrPhase", cdcrPhase]
                    ],
                    completefunc:function (xData, Status) {
                    
                    }
                });

            });
        }
    })

    alert("Completed");
    window.location.reload();
}

May 8, 2012 at 10:25 PM

What does the UpdateListItems operation return? Failure? Success? and if successful, can you post the XML response it returns (which should be the new item created)?


May 9, 2012 at 1:39 AM

Here is what I get back:

#document
xml version="1.0" encoding="utf-8"
0 version 1.0
1 encoding utf-8
soap:Envelope
0 xmlns:soap http://schemas.xmlsoap.org/soap/envelope/
1 xmlns:xsi http://www.w3.org/2001/XMLSchema-instance
2 xmlns:xsd http://www.w3.org/2001/XMLSchema
soap:Body
 
UpdateListItemsResponse
0 xmlns http://schemas.microsoft.com/sharepoint/soap/
UpdateListItemsResult
 
Results
 
Result
0 ID 1,New
ErrorCode 0x810200bf
ErrorText The list item could not be added or updated because duplicate values were found in one or more fields in the list.
May 9, 2012 at 1:41 AM
Check your list definition. Sounds like there is a column that does not allow duplicate values in the list.

_____
Paul

Sent from mobile device.
May 9, 2012 at 2:23 AM

THANK YOU.  I thought I was going mad.  I talked with the other guy working on the site and low and behold he had made one of the columns unique without telling me.  Spent hours banging my head on this.

Learned something new with the Debug xml out put.  Great feature of SPServices that I have not used, but will be going forward.   $().SPServices.SPDebugXMLHttpResult

Thank you and resolved.

May 9, 2012 at 2:32 AM
Glad I could help.

_____
Paul

Sent from mobile device.