0

是否可以通过 rest api 或 JSOM 以编程方式更新 infopath 表单库字段值?如果可以,可以提供样品吗?

我已经尝试过这两种方式,并且两次我都收到了成功消息,尽管在我查看我刚刚尝试更新值的表单的那一刻保持不变。

<script>
  
    //Retrieve list items from sharepoint using API  
    function GetSampleListItems() {  
        siteURL = _spPageContextInfo.webAbsoluteUrl;  
        console.log("from top nav - " + siteURL);  
        var apiPath = _spPageContextInfo.webAbsoluteUrl +"/_api/lists/getbytitle('Training%20Copy')/items/getbyid(9)";  
        $.ajax({  
                url: apiPath,  
                type: "POST",  
                headers: {  
                    Accept: "application/json;odata=verbose"  
                },  
                data: JSON.stringify
                ({
                    __metadata:
                    {
                        type: "SP.Data.Training_x0020_CopyItem"
                    },
                    Position: "Show"
                }), 
                headers: {  
                "Accept": "application/json;odata=verbose",
                "Content-Type": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                "IF-MATCH": "*",  
                "X-HTTP-Method": "MERGE" 
            }, 
            async: false, success: function(data) {  
                alert("Item updated successfully");  
            }, eror: function(data) {  
                console.log("An error occurred. Please try again.");  
            }
        })   
    
    }
</script>

<button onclick="GetSampleListItems();" type="button">Click me​&lt;/button>

4

2 回答 2

0

我不是程序员,也不了解 API,但 InfoPath 表单库中的文档只是带有花哨扩展名的 XML 文本文件。InfoPath 基本上是一个强大的 XML 编辑器。使用任何可以在 XML 层次结构中找到方式的文本编辑方法都应该可以更改这些文件中的值。

但请注意,InfoPath 表单界面中的处理逻辑可用于在显示或编辑表单中的数据时对其进行操作。例如,数据验证或某些字段值根据其他字段的值自动设置。因此,仅通过后端破解字段值可能会导致不良结果。这也可能是您没有看到已应用的更改的原因。

于 2020-10-26T20:00:04.437 回答
0

您可以参考以下文章通过 rest api 或 JSOM 更新 listitem 值:

https://www.codesharepoint.com/jsom/update-listitem-in-sharepoint-using-jsom

https://www.codesharepoint.com/rest-api/update-listitem-in-sharepoint-using-rest-api

于 2020-10-27T09:35:23.960 回答