Adding new items with user values using UpdateListItems

May 10, 2012 at 5:30 PM

I'm having a problem inserting a new record into a list (WSS) that contain SPUser values.

This is what I have:

$().SPServices({
  operation: "UpdateListItems",
  async: false,
  batchCmd: "New",
  listName: "Proxies",
  debug: true,
  updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +
                "<Method ID='1' Cmd='New'>" +
                "<Field Name='ProxyFor'>" + user.login + "</Field>" +
                "<Field Name='User'>" + proxy.login + "</Field>" +
                "</Method>" +
                "</Batch>",
  completefunc: function (xData, Status) {
     alert(xData.responseText);
  }
});    

The values user.login and proxy.login are in the format:  domain\first.lastname

I've tried it with out the domain and I always get the same error: The Operation failed because an unexpected error occurred.

Is there a trick to add SPUser values?

Thank you

May 10, 2012 at 5:50 PM

It might appear that I have to have the names in the following format:  id;#name

May 10, 2012 at 6:51 PM

Yes, at this point, the user is expected to be in the "User Information List" in which they would indeed have an id. If they are not yet in this list, I am not sure you can add them with code in this case.

May 10, 2012 at 7:17 PM

+1 to spevilgenius...

If they aren't in the UIL, then the people picker will not find them.  If I'm not mistaken, you only need the user id when making updates or adds.

 

Cheers,

Matt