UpdateListItems basename

Feb 1, 2012 at 8:45 AM
Edited Feb 1, 2012 at 12:15 PM

Hi Marc,

is it possible to use the spservices updatelistitems to update an existing items folder location to another? I tried the code below, the item was updated but it did not move to the new folder. thanks

basically moving one list item from a folder to another folder.

 

$().SPServices({
        operation: "UpdateListItems",
        async: false,
        listName: "listname",
        updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +
                "<Method ID='1' Cmd='Update'>" +
                    "<Field Name='FSObjType'>0</Field>" +
                    "<Field Name='BaseName'>" + folderName + "</Field>" +
                "</Method>" +
            "</Batch>",
        completefunc: function(xData, Status) {
            …
        }
    });

Coordinator
Feb 1, 2012 at 1:57 PM

Joe:

Check out this thread:
http://spservices.codeplex.com/discussions/287935

I think you guys are trying to do roughly the same thing.

M.

Feb 1, 2012 at 2:24 PM

thanks for that Marc. Ive actually read the thread after posting my question. tried the solution but didnt work. This should be possible right? ive been trying all day BaseName, rootfolder even the filerefs with no luck

Feb 1, 2012 at 3:13 PM

It appears to be failing because you are not targeting a specific item.  To do that you'll have to add the ID to your batch.

$().SPServices({
        operation: "UpdateListItems",
        async: false,
        listName: "listname",
        updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +
                "<Method ID='1' Cmd='Update'>" +
                    "<Field Name='FSObjType'>0</Field>" +
                    "<Field Name='BaseName'>" + folderName + "</Field>" +
                    "<Field Name='ID'>1</Field>" +
                "</Method>" +
            "</Batch>",
        completefunc: function(xData, Status) {
            //...
        }
    });

Feb 1, 2012 at 3:20 PM

iOnline247 thanks. My actual code has the ID field inplace. Im not sure if im having problems with the basename. My list item is within a 2 level folder structure. e.g Country/CompanyName. heres my code

$().SPServices({
        operation: "UpdateListItems",
        async: false,
        listName: "listname",
        updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +
                "<Method ID='1' Cmd='Update'>" +
                    "<Field Name='FSObjType'>0</Field>" +
                    "<Field Name='BaseName'>" + CountryFolder/CompanyFolder/TitleField + "</Field>" +
                    "<Field Name='ID'>1</Field>" +
                    "<Field Name='Title'>Test</Field>" +
                "</Method>" +
            "</Batch>",
        completefunc: function(xData, Status) {
            //...
        }
    });

Feb 1, 2012 at 3:44 PM

Are you trying to create this folder and at the same time move the item to it?

Feb 1, 2012 at 3:48 PM

if the folder does not exist, it creates it first and then at the same time move the item to it. But if the folder is already there, item should be moved to that folder upon saving (in editform.aspx)

Feb 1, 2012 at 7:07 PM

Can you try the code and move it to an existing folder?  I've never tried to create a folder and move an item to it within the same batchCMD.  You may be running into a race scenario.

Feb 2, 2012 at 6:07 AM

tried it still doesnt work. im starting to think that this isnt even possible. were you able to make this work?

Feb 2, 2012 at 11:41 AM

Absolutely.  The code I posted is in production.

Feb 2, 2012 at 12:11 PM

thanks. i dont know what im missing. if i change the CMD to "New" it works. even tried the RootFolder solution

Feb 2, 2012 at 12:26 PM

Can you make your batch a variable and console.log() that.  You'll be able to copy and paste the text from your debugger into here.  That might give us the answer.

Feb 2, 2012 at 12:58 PM

here you go

"<Batch OnError='Continue' PreCalc='TRUE'><Method ID='1' Cmd='Update'> <Field Name='FSObjType'>0</Field><Field Name='BaseName'>United States/test products, Inc</Field><Field Name='ID'>35</Field><Field Name='Title'>tested thid and tsd</Field></Method></Batch>"

Coordinator
Feb 2, 2012 at 2:08 PM

Joe:

You have a comma in your BaseName, and I don't think that's allowed.

M.

Feb 2, 2012 at 3:29 PM

To make your life easy, go to the menu that allows you to create a folder.  In the name of the folder, add a bunch of special characters and press save.  SharePoint will throw an error.  All of the characters listed are the ones you aren't allowed to use, web service or not.

 

Cheers,

Matt

Feb 2, 2012 at 3:55 PM
Edited Feb 2, 2012 at 3:55 PM

the odd thing is, the code i posted works with new CMD batch. even with the comma. If i remove /test products, inc and just leave united states as the folder destination, it still does not move the item to the folder but it does save the edited fields

Feb 2, 2012 at 4:22 PM

Going to set this up on my lunch...  I'll post my results and full code as well.

Feb 2, 2012 at 4:28 PM

oh really appreciate it iOnline247 thanks so much

Feb 2, 2012 at 8:13 PM

Ugh... I'm having troubles moving items from folder to folder.  I can create them wherever I want, but moving them is not working for me (I'm on 2010 now).  It's very strange too, b/c this code is working in a production environment (2007).

Let me ping JB and see what he has to say.  He played a big part in the solution we provided, so he should have invaluable feedback.

Cheers,
Matt 

Feb 3, 2012 at 1:18 AM

I think I remember now what we did to move items.  Sorry (big egg on my face), it has been a long time since needing to do that and looking at the code sample I had, it wasn't very clear from a quick glance, exactly how it was handled.

We did a wholesale copy of the item, delete, then added a new one in the folder where we wanted it to go.  I was successful in creating a new item in any directory I wanted, so it's possible.  We weren't worried about ID's, so if that matters to you, then it'd be impossible (I think) via web services to do this.

 

When JB has a chance, he said he would look over this thread and clarify.  He still has access to the full codebase if I'm not mistaken.

 

Marc any item/folder web service magic on your end?

Feb 3, 2012 at 4:42 AM

thanks iOnline247. Actually thats my first solution, delete then add a new one in the folder which im trying to  avoid :) might run into ID problems with the client but if its really impossible via web services then it will have to do. still hoping for a solution thought. thanks again for your help