event receiver assign people/group column value from list to people/group field in another list

gogi100 46 Reputation points

i have two lists. the event receiver have to assign value (its a group) from people/group field from one list to people/group field in another list. my code is

SPQuery upitponude = new SPQuery();
                upitponude.Query = "<Where><Eq>" + "<FieldRef Name='ID' />" + "<Value Type='Text'>" + idponudesmestajZ + "</Value>" + "</Eq>" + "</Where>";
                SPListItemCollection kolekcijaponudaizPonudeSmestajZbirno = PonudeSmestajZbirno.GetItems(upitponude);
                foreach (SPListItem ponuda in kolekcijaponudaizPonudeSmestajZbirno)
                    SPGroupCollection group = properties.Web.Groups;
                    int brojgrupa = group.Count;
                    for (int i = 1; i <= brojgrupa; i++)
                        if (group[i].Name == ponuda["ТИМ"].ToString())
                            SPFieldUserValueCollection value = new SPFieldUserValueCollection();
                            value.Add(new SPFieldUserValue(properties.Web, group[i].ID, group[i].Name));
                            properties.ListItem["ТИМ"] = value;

value of ponuda["ТИМ"].ToString() every time is null. this field in list has value(the group).
what i do?

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
1,785 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,430 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,500 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. gogi100 46 Reputation points

    the other values in SPListItem 'ponuda' like:


    have values, just ponuda["ТИМ"] has not value.

    0 comments No comments

  2. RaytheonXie_MSFT 19,726 Reputation points Microsoft Vendor

    Hi @gogi100 ,
    First we need to confirm the type of column "ID".It's "<Value Type='Number'>" as usual. If the type wrong,we will get Multiple groups and the group is FieldUserValue.
    We can't get the value correctly.
    Then we need to check multiple selections as "no" like following in list setting,or it will return a collection.This option can also affect the way we retrieve group value.
    Finally we can use following code to get single group

    SPFieldUserValue groups = (SPFieldUserValue)ponuda["ТИМ"];  
    if (group[i].Name == groups.LookupValue){  

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.