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

gogi100 51 Reputation points
2021-09-08T19:30:36.997+00:00

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.
2,190 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,565 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,785 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. gogi100 51 Reputation points
    2021-09-09T07:14:07.65+00:00

    the other values in SPListItem 'ponuda' like:

    ponuda["година"]
    ponuda["сектор"]
    ...

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

    0 comments No comments

  2. RaytheonXie_MSFT 30,186 Reputation points Microsoft Vendor
    2021-09-09T09:57:53.643+00:00

    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.
    130702-image.png
    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.