Populating a Multi Person/Group field w/ People Search results

Feb 14, 2012 at 4:36 PM

I have a newform that managers use that I pull the current user info to prefill with data such as Company, Office, etc, and needed to load their direct reports as well (Employees column, multiple select Person/Group field .

I cobbled together a Search web service that returns the employees, which I deduced needed to be loaded in a certain format for the field to accept without their ID, and it works great!  The format that works is:

-1;#PreferredName1;#-1;#PreferredName2;#-1;#PreferredName3;# and so on.

This works 90% of the time, with the following exception - if any one of the users has an inactive Active Directory account, SharePoint does not pull them in, so the field is left blank on the form.

As an interim, I have split the code into two pieces, one to prefill and save with all the fields except the Employees, then to go back into the item and update the Employees column.

Is there anyway to pass the value into UpdateMultipleListItems for the field as an array?  And if I update, won't it just overwrite each previous value?

Here is the pertinent chunk of my code, including the Query, building the text string to plop into the Employees field, and the double update.  This code works, unless any one or more Employees account  is inactive.

Thanks!

Bill

var queryText = "<QueryPacket xmlns='urn:Microsoft.Search.Query' Revision='1000'><Query><Context><QueryText language='en-US' type='MSSQLFT'>SELECT Title, Path, Description, Write, Rank, Size  FROM SCOPE() WHERE \"scope\" = 'People' AND Manager LIKE '%" + supvName + "'</QueryText></Context><Range><StartAt>1</StartAt><Count>25</Count></Range></Query></QueryPacket>";


    $().SPServices({
         operation: "Query",
         queryXml: queryText,
          completefunc: function(xData, Status) {
         
            var queryResult = $(xData.responseXML).find("QueryResult").text();
            var xml = $("<xml>" + queryResult + "</xml>");

                xml.find("Property").find("Name[text=TITLE]").each(function()
                 {
                 employ = ($(this).parent().find("Value").text());

                  switch (employ)
                   {
                    case "":
                     employees = "-1;#" + employ + ";#";
                     break;
                    default:
                     employees = employees + "-1;#" + employ + ";#";
                     break;
                   }

                 });

$().SPServices.SPUpdateMultipleListItems({
  listName: "{9024B1C9-BB0E-46C5-96D5-F5CEF3FFC296}",
  CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + lastId + "</Value></Eq></Where></Query>",
  valuepairs: [["Observer", "-1;#" + pName],["Supervisor","-1;#"+ sName],["Manager","-1;#"+ mName],["Office",officeId + ";#" + office],["BusinessUnit",companyId + ";#" + company],["Process",processId + ";#" + process],["SafetySpecialist",safeSpecialist]]

});

$().SPServices.SPUpdateMultipleListItems({
  listName: "{9024B1C9-BB0E-46C5-96D5-F5CEF3FFC296}",
  CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + lastId + "</Value></Eq></Where></Query>",
  valuepairs: [["Employee",employees]]

});



           }
       });