Hi @Anna,
The error message suggests that the "field" parameter in your request is null or empty, which is causing the "ArgumentNullException" exception.
To resolve this issue, make sure you provide a valid value for the "field" parameter in the request body.
Please replace 'FieldName' with the actual internal name of the field you want to move within the view.
Make sure to provide a valid field name that exists in the view.
Here is a test for your reference:
<button onclick="SetListViewTitle();" type="button" unselectable="on">Click me</button>
<script src="https://MyServer/sites/SiteCollection/style library/js/ScriptFile.js"></script>
<script>
function SetListViewTitle() {
var listTitle = 'Fctest List';
var viewTitle = 'test1';
var fieldInternalName = 'DisplayImage';
var fieldIndex = 1;
// Get the view by title
var viewUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('" + listTitle + "')/views/getByTitle('" + viewTitle + "')";
$.ajax({
url: viewUrl,
method: "GET",
headers: { "Accept": "application/json;odata=verbose" },
success: function (viewData) {
// Update the field within the view
var viewFieldsUrl = viewData.d.__metadata.uri + "/ViewFields/MoveViewFieldTo";
$.ajax({
url: viewFieldsUrl,
method: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify({ "field": fieldInternalName, "index": fieldIndex }),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
console.log("Field moved successfully within the view.");
},
error: function (xhr, status, error) {
console.log("Failed to move the field within the view. Error: " + error);
}
});
},
error: function (xhr, status, error) {
console.log("Failed to retrieve the view. Error: " + error);
}
});
}</script>
Here is test result:
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in [our documentation] to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards
Cheng Feng