none
How to add people and groups from email id RRS feed

  • Question

  • Hi

    I have a column which has email id of user\s, 

    I would like to create another person and groups column and convert the email ids from the email id column to people and groups datatype data.

    is it possible? if not how about display name?

    one is text filed which is populated with email id other field is people picker. I want all the text field which consists of email to be converted and added to people picker. 

    I have an asp.net application which populated the text field with email id. But the principle is not the same when it comes to people picker column. please see the code below.

    item["Full_x0020_Name"] = empname.Replace('.', ' ');
                            item["Emp_x0020_ID"] = summarydr.EMPLOYEEID.ToString();
                            item["Location"] = summarydr.Location.ToString();
                            item["Division"] = strDivision;
                            item["Department"] = summarydr.PROFESSION;
                            item["Professional_x0020_Title"] = summarydr.POSITION;
                            item["employment_x0020_status"] = true;
                            item["Revision"] = DateTime.Now.Year.ToString();
                            item["Years_x0020_of_x0020_Experience"] = summarydr.TOTALYRSEXP;
                            //item["Experience_x0020_Type"] = str.TrimEnd(',');
                            item["Experience_x0020_Type"] = strExptype;
                            item["CVBuilder"] = "Yes";
                            item["CV_x0020_Coordinator_x0020_Email"] = "Myname@host.com";
    
    
                            //this is the people or group column
                            //item["CV_x0020_Coordinator"] = "Userid";
                            item.Update();
                            uploadFile.CheckIn(string.Empty, CheckinType.OverwriteCheckIn);
                            Context.ExecuteQuery();



    • Edited by roma_victa Wednesday, September 18, 2019 6:08 AM
    Wednesday, September 18, 2019 5:33 AM

All replies

  • Hi,

    If user email address map to valid SharePoint online user, get user by CSOM.

    Sample code:

    Web web = context.Web;
                    var _User = web.EnsureUser("user@tenant.onmicrosoft.com");
                    context.Load(_User);
                    context.ExecuteQuery();

    Then, update the user value to multiuser field.

    https://piyushksingh.com/2014/01/19/update-a-usermulti-column-value-in-client-object-model-c/

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, September 18, 2019 7:42 AM
  • Hi Lee,

    Thanks for the Update,

    can we use it like this 

    Web web = Context.Web;
                            var _User = web.EnsureUser("user@tenant.onmicrosoft.com");
                            Context.Load(_User);
                            Context.ExecuteQuery();
                            item["CV_x0020_Coordinator"] = _User;
                            item.Update();
                            uploadFile.CheckIn(string.Empty, CheckinType.OverwriteCheckIn);
                            Context.ExecuteQuery();



    • Edited by roma_victa Wednesday, September 18, 2019 8:09 AM
    Wednesday, September 18, 2019 8:07 AM
  • Hi,

    Don't set user to user field directly.

    If the user field is single user field, use FieldUserValue to update the field value.

    FieldUserValue userValue = new FieldUserValue();
    userValue.LookupId = User.Id;
    item["userField"] = userValue;
    item.Update();

    Best Regards,

    Lee



    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, September 18, 2019 8:28 AM
  • To sum up

                            item["Full_x0020_Name"] = empname.Replace('.', ' ');
                            item["Emp_x0020_ID"] = summarydr.EMPLOYEEID.ToString();
                            item["Location"] = summarydr.Location.ToString();
                            item["Division"] = strDivision;
                            item["Department"] = summarydr.PROFESSION;
                            item["Professional_x0020_Title"] = summarydr.POSITION;
                            item["employment_x0020_status"] = true;
                            item["Revision"] = DateTime.Now.Year.ToString();
                            item["Years_x0020_of_x0020_Experience"] = summarydr.TOTALYRSEXP;
                            //item["Experience_x0020_Type"] = str.TrimEnd(',');
                            item["Experience_x0020_Type"] = strExptype;
                            item["CVBuilder"] = "Yes";
                            item["CV_x0020_Coordinator_x0020_Email"] = summarydr.CV_CoordinatorEmail;
    
    
                            Web web = Context.Web;
                            var _User = web.EnsureUser(summarydr.CV_CoordinatorEmail);
    
                            FieldUserValue userValue = new FieldUserValue();
                            userValue.LookupId = _User.Id;
                            item["CV_x0020_Coordinator"] = userValue;
                            item.Update();
                            uploadFile.CheckIn(string.Empty, CheckinType.OverwriteCheckIn);
                            Context.ExecuteQuery();
     

    I got an error 

    The property or field 'Id' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. on the below line 

     userValue.LookupId = _User.Id;



    • Edited by roma_victa Wednesday, September 18, 2019 9:31 AM
    Wednesday, September 18, 2019 9:17 AM
  • Hi,

    You need load the user first to get user id.

    var _User = web.EnsureUser("user@tenant.onmicrosoft.com");
    Context.Load(_User);
    Context.ExecuteQuery();

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, September 19, 2019 2:03 AM