Skip to content

How to write hyperlink custom field in a SharePoint list #2957

@zorgoz

Description

@zorgoz

Describe the bug

Unable to write SPO Hyperlink custom field. Getting Invalid request error.

Expected behavior

Field to be updated.

How to reproduce

  • Cereata a list in SPO
  • Add a hyperlink custom field, name URL
  • Add two rows, complete the URL field for one, and leave it empty for the other.
  • Prepare a graphClient instance
var items = await graphClient
    .Sites["siteId"]
    .Lists["listId"]
    .Items
    .GetAsync(requestConfiguration =>
    {
        requestConfiguration.QueryParameters.Expand = new[] { "fields" };
        requestConfiguration.QueryParameters.Top = 100;
    });

foreach (var item in items.Value)
{
    var fields = item.Fields?.AdditionalData;

    if (fields == null) continue;
    
    if (fields.TryGetValue("URL", out var _url) && _url is UntypedObject uo) // testing read
    {
        foreach (var (name, node) in uo.GetValue())
        {
            var scalarAsString = await KiotaJsonSerializer.SerializeAsStringAsync(node);
            $"{name}: {scalarAsString}".Dump();
        }

        continue;
    }

    var table = new UntypedObject(new Dictionary<string, UntypedNode>
    {
        ["url"] = new UntypedString("whateverurl"),
        ["description"] = new UntypedString("whatevertext"),
    });

    var updateFields = new FieldValueSet
    {
        AdditionalData = new Dictionary<string, object>
        {
            ["URL"] = table,
        }
    };

    await graphClient
        .Sites[siteId]
        .Lists[listId]
        .Items[item.Id]
        .Fields
        .PatchAsync(updateFields);
}
  • The completed cell can be read back
  • The patch throws an exception

SDK Version

5.87.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

No response

Configuration

Windows 10, x64, nothing specific

Other information

ref: https://stackoverflow.com/questions/79714772/how-to-write-hyperlink-custom-field-in-a-sharepoint-list-using-graphapi

Sample on read ("Server" is also a custom field, which I can write using the same method):
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions