0

i wrote a simple batch operation to test if i can add items to list, but i always get error.

            string batchFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ows:Batch OnError=\"Return\">{0}</ows:Batch>";

            string methodFormatTest = "<Method ID=\"1\"" +
                "<SetList>69f72fe7-1270-4e70-b3f5-11ed8ea05fea</SetList>" +
                //"<SetVar Name=\"Cmd\">Save</SetVar>" +
                //"<SetVar Name=\"ID\">New</SetVar>" +
                //"<SetVar Name=\"urn:schemas-microsoft-com:office:office#Title\">Text</SetVar>"

                 //"<SetVar Name=\"AuteurMetallurgyNuance\">Name</SetVar>" +
                 "<SetVar Name=\"IDMetallurgyNuance\">777</SetVar>" +
                 "</Method>";

            batch = string.Format(batchFormat, methodFormatTest);
            string batchReturn = web.ProcessBatchData(batch);

The erorr that i get is:

69f72fe7-1270-4e70-b3f5-11ed8ea05fea Invalid URL Parameter.

The URL provided contains an invalid Command or Value. Please check the URL again.

The question is, if the field is required and i dont fill it, can it cause an error?

Are this required? Save New

For testing i just want to add fill one field and save item.

UPDATE: I created an custom list, with only one field "Title" to test, so i execute the next batch :

            SPList list2 = web.Lists["Test"];
            string listGuid2 = list2.ID.ToString();
            string methodFormatTest2 = "<Method ID=\"1\" Cmd=\"New\"" +
                "<SetList>"+listGuid2+"</SetList>" +
                "<SetVar Name=\"Title\">New</SetVar>" +
                 "</Method>";

But i still get an error:

<Results>16032391-301a-4586-b6b3-2f0a6f0cfcae<Result ID="1" Code="-2130575350">
<ErrorText>Invalid URL Parameter.

The URL provided contains an invalid Command or Value. Please check the URL again.</ErrorText></Result>
</Results>

So help is still needed, if anyone has any suggestions!

UPDATE 2: I did test on an custom list and it added the title, now im trying this on my custim list, but it fails, it adds just empty rows, how is this possible?

Schema for the list:

 <Field ID="{93CF7259-2031-49B8-94E2-714A786F67AA}" Name="ID" Type="Text" DisplayName="ID" Group="V" Required="TRUE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" Indexed="TRUE" />
      <Field ID="{A122D632-9D29-47FE-84A1-8609B94AF86C}" Name="Auteur" Type="Text" DisplayName="Auteur" Group="V" Required="FALSE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" Indexed="TRUE" />
      <Field ID="{813B6A47-A0AC-46DD-912E-CBABE499D617}" Name="Reference" Type="Text" DisplayName="Reference" Group="V" Required="FALSE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" Indexed="TRUE" />
      <Field ID="{776862E6-17F7-4CC6-9D70-6C63C6895887}" Name="TypeDo" Type="Text" DisplayName="Type Document" Group="V" Required="FALSE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" Indexed="TRUE" />

And here is the code:

st

ring methodFormatTest = "<Method ID='775' Cmd='Save'>" +
                "<SetList>" + listGuid + "</SetList>" +
                "<SetVar Name='Cmd'>Save</SetVar>" +
                 "<SetVar Name='ID'>New</SetVar>" +
                 "<SetVar Name='urn:schemas-microsoft-com:office:office#Title'>titletitle</SetVar>" +
             "<SetVar Name='ID'>id</SetVar>" +
             "<SetVar Name='Auteur'>auteur</SetVar>" +
             "<SetVar Name='Reference'>ref</SetVar>" +
              "<SetVar Name='TypeDocMetallurgyNuance'>type</SetVar>" +
             "</Method>";
    batch = string.Format(batchFormat, methodFormatTest);
    string batchReturn = web.ProcessBatchData(batch);

So when i execute this it adds an empty row ... any idea?

2 Answers 2

1

To create a new item, You still need to specify the Cmd as Save, and provide New for the ID.

SPList list2 = web.Lists["Test"];            
string listGuid2 = list2.ID.ToString();             
string methodFormatTest2 = "<Method ID=\"1\" Cmd=\"Save\"" +     
    "<SetList>"+listGuid2+"</SetList>" +
    "<SetVar Name=\"ID\">New</SetVar>" +                
    "<SetVar Name=\"Title\">New</SetVar>" +                  
    "</Method>";

Paul.

2
  • its cmd = save and not new?
    – Shkipper
    Mar 14, 2012 at 14:57
  • Yep, take a look at this msdn article which shows an example in the first code block.
    – Cimares
    Mar 14, 2012 at 17:25
0
<?xml version=\'1.0\' encoding=\'UTF-8\'?>  
<ows:Batch OnError=\'Continue\'>  
    <Method ID=\'1\'>  
        <SetList>37c797c9-6feb-471e-a872-9407a760a21e</SetList>  
        <SetVar Name=\'Cmd\'>Save</SetVar>  
        <SetVar Name=\'ID\'>New</SetVar>  
        <SetVar Name=\'urn:schemas-microsoft-com:office:office#Title\'>abc</SetVar>  
        <SetVar Name=\'urn:schemas-microsoft-com:office:office#Cmt\'>abc</SetVar>  
    </Method>  
</ows:Batch>

This will insert values into two fileds namely Title and Cmd.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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