2

I have a SharePoint List that I am able to successfully connect to via the Graph API. It pulls the list items but seems only to be showing the base data. How to I get to the fields and the data that is contained in those fields so that I can display / update that data?

Also, I assume the SPO Graph API enpoint is: https://graph.microsoft.com/v1.0/

var assetlist = await graphClient
    .Sites[AllCompanySiteID]
    .Lists[CurrentBuildsListID]
    .Items
    .Request()
    .GetAsync();

totalitems.AddRange(assetlist.CurrentPage);

while (assetlist.NextPageRequest != null)
{
    assetlist = assetlist.NextPageRequest.GetAsync().Result;
    totalitems.AddRange(assetlist.CurrentPage);
}

1 Answer 1

3

It's unclear whether you want to (1) Get Data Fields only and Update Data Fields only or (2) you need to Update Data Fields from Selection - when in doubt I'll write both approaches. If your requirement is item (2), you may want to map/model the business rule to develop the routine. According to Microsoft Docs, the following examples:

(1) Get Data Fields only:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var queryOptions = new List<QueryOption>()
{
    new QueryOption("expand", "fields(select=Field1,Field2,Field3)")
};

var items = await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items
    .Request( queryOptions )
    .GetAsync();

(1) Update Data Fields only:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var fieldValueSet = new FieldValueSet
{
    AdditionalData = new Dictionary<string, object>()
    {
        {"Field1", "Test1"},
        {"Field2", "Test2"}
    }
};

await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items["{listItem-id}"].Fields
    .Request()
    .UpdateAsync(fieldValueSet);

(2) Update Data Fields from Selection example:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );
    
    var queryOptions = new List<QueryOption>()
    {
        new QueryOption("expand", "fields(select=Field1,Field2,Field3)")
    };
    
    var items = await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items
        .Request( queryOptions )
        .GetAsync();
foreach(var item in items)
{
    //an example of Business Rule: Update item based by some Select into current item
    if(null != item.Fields.AdditionalData["Field1"] && !string.IsNullOrWhiteSpace(item.Fields.AdditionalData["Field1"].ToString()))
    {
        var fieldValueSet = new FieldValueSet
        {
            AdditionalData = new Dictionary<string, object>()
            {
                {"Field2", "Test2"},
                {"Field3", "Test3"}
            }
        };
        await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items[item.Id.ToString()].Fields
        .Request()
        .UpdateAsync(fieldValueSet);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, thank you! I didn't realize how much data there is associated with a list item.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.