SharePoint的图形API:使用超链接/图片字段更新/创建ListItems

问题描述 投票:0回答:1

我如何调整有效载荷的大小以为超链接/图片字段启用发布或补丁程序?

直接获得这些字段:它们以“ fieldName”:{“ Description”:“ asdf”,“ Url”:“ asdf.com”}

这可以通过使用向SharePoint发送HTTP请求块来实现,但是我无法弄清楚如何使用图api来完成这项工作。我是否需要显式设置odata类型(SP.FieldUrlValue不起作用),它对超链接有什么作用?

Somethink像这样:{“ [email protected]”,“ Complex”}-例如,我们将它与Collection(Edm.String)一起用于多个查找字段。

亲切的问候,格雷格

microsoft-graph sharepoint-online
1个回答
0
投票

Graph API不支持创建此类列。

https://docs.microsoft.com/en-us/graph/api/resources/columndefinition?view=graph-rest-1.0

您可以尝试使用rest api。

创建HyperLink字段:

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
$(function (){
CreateListItemWithDetails("test3")
})
function CreateListItemWithDetails(listName) {
    var itemType = GetItemTypeForListName(listName);
    var item = {
        "__metadata": { "type": itemType },
        "Title": "test",
        'link': 
                {
                    '__metadata': { 'type': 'SP.FieldUrlValue' },
                    'Description': 'Google',
                        'Url': 'http://google.com'
                    },
        };



        $.ajax({
            url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
            type: "POST",
            contentType: "application/json;odata=verbose",
            data: JSON.stringify(item),
            headers: {
                "Accept": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },
            success: function (data) {
                console.log(data);
            },
            error: function (data) {
                console.log(data);
            }
        });
    }




// Get List Item Type metadata
function GetItemTypeForListName(name) {
    return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
}
</script>

更新超链接列:

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
$(function (){
CreateListItemWithDetails("test3")
})
function CreateListItemWithDetails(listName) {
    var itemType = GetItemTypeForListName(listName);
    var item = {
        "__metadata": { "type": itemType },
        "Title": "test",
        'link': 
                {
                    '__metadata': { 'type': 'SP.FieldUrlValue' },
                    'Description': 'Google1',
                    'Url': 'http://google.com'
                },
    };



    $.ajax({
        url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items(41)",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "MERGE",
           "If-Match": "*"
        },
        success: function (data) {
            console.log(data);
        },
        error: function (data) {
            console.log(data);
        }
    });
}



// Get List Item Type metadata
function GetItemTypeForListName(name) {
    return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
}
</script>
© www.soinside.com 2019 - 2024. All rights reserved.