是否可以通过 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</button>