Grab person loginname and Name from a Person Column in Javascript

Unanswered Grab person loginname and Name from a Person Column in Javascript

  • sexta-feira, 3 de agosto de 2012 00:53
     
      Contém Código

    Hello,

    I'm trying to pull the information from a Custom Lists Multiple Person field in JavaScript.

    Here is the test JavaScript code I'm using to push users into a Person Field within the list :

    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('SomeListName');
    this.oListItem = oList.getItemById(getID);
    var users = new Array();
    users.push(SP.FieldUserValue.fromUser("domain\\user1"));
    users.push(SP.FieldUserValue.fromUser("domain\\user2"));
    oListItem.set_item('Contacts', users);   
    oListItem.update();
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onSetSucceeded), Function.createDelegate(this, this.onSetFailed));

    And I can pull users out in C# like this:

     SPFieldUserValueCollection fieldUserValues = new SPFieldUserValueCollection();
                    SPQuery userQuery = new SPQuery();
                    userQuery.ViewFieldsOnly = true;
                    userQuery.RowLimit = 1;
                    userQuery.ViewFields = "<FieldRef Name='Contacts' />";
                    userQuery.Query = "<Where><Eq><FieldRef Name='Author' /><Value Type='Integer'><UserID Type='Integer' /></Value></Eq></Where>";
                    SPListItemCollection listItems = registrationList.GetItems(userQuery);
                    if (listItems.Count > 0)
                    {
                        SPFieldUserValueCollection fieldUserValueCollection = (SPFieldUserValueCollection)listItems[0]["Contacts"];
                        foreach (SPFieldUserValue targetContact in fieldUserValueCollection)
                        {
                            retVal.Add(targetContact.User.Name, targetContact.User.LoginName);
                        }
                    }

    But I need to do this in JavaScript rather than C#.

    I've not been able to locate much in the way of solid documentation on this... So, any pointers or code samples would be great on how to pull users (could be more than one) from a Lists People column in a custom list would be great.

    Thanks

Todas as Respostas