While creating Item Graph query throws an error when PersonOrGroup entry I add in a item AdditionalData's Dictionary object?

Anonymous
2022-07-13T06:47:26.68+00:00

0

Entry of a dictionary is -

tempDict.Add(field.Key, field.Value); //tempDict.Add(Speakers, [{"LookupId":6,"LookupValue":"Sonam Giwad","Email":"******@NetVaultPlugIn2.onmicrosoft.com"}])  

graph query is -

Microsoft.Graph.ListItem newItem = RetryIfThrown<Exception, Microsoft.Graph.ListItem>(() =>  
            {  
                return graphServiceClient.Sites[SiteId].Lists[ListId].Items.Request().AddAsync(item).Result;  
            });  
Microsoft 365 and Office SharePoint For business Windows
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-07-18T08:55:29.597+00:00

    Hi anonymous user ,
    I'm glad to hear you solve the problem ,if you have any issue about SharePoint, you are welcome to raise a ticket in this forum.

    By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others." and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread:

    Issue Symptom:
    While creating Item Graph query throws an error when PersonOrGroup entry I add in a item AdditionalData's Dictionary object

    Current status:
    It's resolved by following code
    Using Server Object model:

    using Microsoft.SharePoint;    
    SPSite site = new SPSite("SiteName");    
    SPWeb web = site.OpenWeb();    
    SPList list = web.Lists["ListName"];    
    string testName = "Manish Loke"; //use display name instead of login name    
    if (testName != "") {    
        SPUser userTest = web.EnsureUser(testName);    
        testName = userTest.ID.ToString() + ";#" + userTest.LoginName.ToString();    
        SPItem item;    
        item["ColumnName"] = testName;    
        item.Update();    
    }    
    

    Using Client object model:

    using Microsoft.SharePoint;    
    using Microsoft.SharePoint.Client;    
    ClientContext context = new ClientContext("SiteName");    
    List list = context.Web.Lists.GetByTitle("ListName");    
    ListItem item;    
    context.Load(list);    
    context.ExecuteQuery();    
    string testName = "Manish Loke"; //use display name instead of login name    
    if (testName != "") {    
        User userTest = context.Web.EnsureUser(testName);    
        context.Load(userTest);    
        context.ExecuteQuery();    
        testName = userTest.Id.ToString() + ";#" + userTest.LoginName.ToString();    
        ListItem item;    
        item["ColumnName"] = testName;    
        item.Update();    
        context.ExecuteQuery();    
    }    
    

    You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!


1 additional answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-07-15T09:21:44.5+00:00

    Hi anonymous user ,
    We need to use userlookupid to update the user column like following

    var expenseItem = new ListItem  
    {  
        Fields = new FieldValueSet  
        {  
            AdditionalData = new Dictionary<string, object>  
            {  
                {"EmployeeLookupId", userLookupId}  
            }  
        }  
    };  
      
    await _graph  
        .Sites["<siteid>"]  
        .Lists["Expenses"]  
        .Items  
        .Request()  
        .AddAsync(expenseItem);  
    

    We don't need to use lookupvalue and email to update the item


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.