Reputation: 143
Is it possible to update infopath form library field values programmatically either through rest api or JSOM? If so can you provide a sample?
I've tried it both ways, and both times I'm getting success messages although the moment I review the form I just attempted to update the values remain the same.
<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>
Upvotes: 0
Views: 398
Reputation: 3655
You could refer to the following articles to update listitem values through rest api or JSOM:
https://www.codesharepoint.com/jsom/update-listitem-in-sharepoint-using-jsom
https://www.codesharepoint.com/rest-api/update-listitem-in-sharepoint-using-rest-api
Upvotes: 0
Reputation: 35915
I'm not a programmer and I don't know about APIs, but the documents in an InfoPath forms library are just XML text files with a fancy extension. InfoPath is basically an XML editor on steroids. Changing values in these files should be possible with any text editing approach that can find its way around the XML hierarchy.
Be aware, though, that the processing logic in the InfoPath form interface may be used to manipulate data in the form when it is displayed or edited. E.g, data validation or some field values getting set automatically depending on the value of other fields. So just hacking field values through the back-end may lead to undesired results. This may also be the reason that you don't see changes you have applied.
Upvotes: 0