Answered SharePoint 2010 - Javascript - Update people and group column

  • Tuesday, August 07, 2012 12:37 AM
     
     

    Hello,

    I'm trying to update a "users and groups" list column using javascript and the client object model. I need to be able to both delete or add the current user to that column.

    So far, I'm using the web.get_currentUser() to get the login user. When adding the user using the set_field command, it simply overwrites the other existing user, what I need is for it to append the current user instead...

    To delete, I need to loop through the existing users,  remove the current user from the list and update the item. I haven't been able to do either add or delete so far.

    I've tried using a workflow. I'm able to append the user to the list using the set field in current item action and simply add a ; between the existing users and the new user... I was not able to remove the user from the list though...

    Any help would be appriciated.




    • Edited by Sofiane Ben Tuesday, August 07, 2012 12:38 AM
    • Moved by GreggPJ - MSFT Thursday, August 09, 2012 1:48 PM moving to right queue (From:SharePoint 2010 - Using SharePoint Designer, Infopath, and other customization)
    •  

All Replies

  • Thursday, August 09, 2012 1:38 AM
    Moderator
     
     

    Hi,

    Thank you for your post.
    I'm trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thanks ,
    Entan Ming


    Entan Ming

    TechNet Community Support

  • Thursday, August 23, 2012 12:20 PM
     
     Answered

    Hi Sofiane Ben,

    You can find an example of adding multiple users to a field using the Client Object Model here:

    http://social.msdn.microsoft.com/Forums/lv-LV/sharepoint2010general/thread/5183e87c-ee1d-4594-9492-0dfdf6616cce

    The example code is written in .NET, but will easily translate into JavaScript. You can use the technique demonstrated to remove users as well, by reading the values of the field, removing the users you don't want, then performing an update.


    David Wilborn MSFT