Transferring a Sharepoint 2010 List Item between folders

Currently, I am facing an issue while attempting to transfer a list item from one folder to another. Despite utilizing a code that I discovered (the link to the source of the code can be found below), I keep encountering an error message stating "Value does not fall within the expected range." which perplexes me. Can someone please shed some light on this problem for me? Thank you!

var listTitle = "Requests"; //list title
var itemId = 1;  //list item id
var targetFolderUrl = "/Lists/Requests/Archive";  //target folder server relative url

var ctx = SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle(listTitle);
var item = list.getItemById(itemId);
ctx.load(item,['FileRef','FileDirRef']);
ctx.executeQueryAsync(
   function(){
       var fileUrl = item.get_item('FileRef');
       var file = ctx.get_web().getFileByServerRelativeUrl(fileUrl);
       var targetfileUrl = fileUrl.replace(item.get_item('FileDirRef'),targetFolderUrl); 
       file.moveTo(targetfileUrl, SP.MoveOperations.overwrite);
       ctx.executeQueryAsync(
          function(){
             console.log('List item has been moved');   
          },
          logError
       )
   },
   logError);


function logError(sender,args){
      console.log(args.get_message()); 
}

This is the actual code I have implemented.

var targetFolderUrl = "/Lists/" + COMM.PROPERTY.SUSAR.LIST + "/ProductID_64";  //target folder server relative url

            var ctx = SP.ClientContext.get_current();
            var list = ctx.get_web().get_lists().getByTitle(COMM.PROPERTY.SUSAR.LIST);
            var item = list.getItemById(66);
            ctx.load(item, ['FileRef', 'FileDirRef']);
            ctx.executeQueryAsync(
               function () {
                var fileUrl = item.get_item('FileRef');
                var file = ctx.get_web().getFileByServerRelativeUrl(fileUrl);
                var targetfileUrl = fileUrl.replace(item.get_item('FileDirRef'), targetFolderUrl);
                file.moveTo(targetfileUrl, SP.MoveOperations.overwrite);
                ctx.executeQueryAsync(
                   function () {
                    console.log('List item has been moved');
                   },
                   logError
                )
               },
               logError);


            function logError(sender, args) {
                console.log(args.get_message());
            }

Guidance on moving list items into folders in SharePoint online

Answer №1

If you prefer to accomplish this task without writing code, you have the option of utilizing a 2010 workflow. In the workflow, you can specify that if the current item equals X, you want to copy the item from the Current Item to a NewList, and then delete the item from the Current Item list. Make sure to select the 2010 workflow instead of the 2013 version for this specific task. Additionally, it may be necessary to configure the trigger for when a new item is created or changed. For example, I have a receiving list that examines a parameter and routes it to one of several possible lists based on that parameter; in this case, I have set up the workflow to trigger on item creation or change events.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you explain the distinction between the "DOMContent event" and the "load event"?

Within Chrome's Developer tool, there is a blue vertical line marked "DOMContent event fired", as well as a red line labeled "load event fired". Is it safe to assume that the "DOMContent event fired" signifies the initiation of inline JavaScript execu ...

How come my web page is not displaying the guages from guage.js?

I am utilizing guage.js to create a graph based on this Fiddle. However, upon adding the same code to my website, the rendering does not appear as expected: https://i.sstatic.net/fIkQr.png Upon inspecting in Chrome developer tools, I noticed that the ele ...

Effortless pagination across various pages, utilizing diverse CSS selectors

I've integrated simple pagination into my website, but I've encountered a issue. My navigation consists of CSS tabs, each holding a unique pagination component. Here is the jQuery pagination code snippet: $(function(){ var perPage = 8; var open ...

Error message in React JSX file: "Encountered an issue with 'createElement' property being undefined"

In the file test_stuff.js, I am executing it by using the command npm test The contents of the file are as follows: import { assert } from 'assert'; import { MyProvider } from '../src/index'; import { React } from 'react'; ...

The VueRouter is unresponsive and not functioning as expected

I have been delving into Vue. Through the npm install vue-router command, I added vue-router to my project. Subsequently, I incorporated VueRouter and defined my URL paths within the VueRouter instances located in the main.js file. I created an About compo ...

Using Angular.js to fetch information from a MySQL database

I'm currently trying to retrieve data from a MySQL database in an Angular.js application. I have gone through multiple tutorials, but unfortunately, none of them have been successful for me. I have a PHP script that returns a JSON array with example ...

Tips for Including a Parallax Image Within a Parallax Section

Currently, I am working on implementing a parallax effect that involves having one image nested inside another, both of which will move at different speeds. My progress has been somewhat successful, however, the effect seems to only work on screens narrowe ...

initiate a click event within another click event

This is an HTML Code snippet: <ul id="linkjess"> <li><a href="javascript:setfolder('medewerkers', '1000');">medewerkers 1000</a></li> <li><a href="javascript:setfolder('medewerkers', ...

GraphQL and Relay.js issue: Error Message: Field "id" is expected in "Node"

It appears that the discrepancy lies in naming conventions between my schema.js file and the database field. The 'id' field in the schema is actually named differently in the database. var classroomType = new GraphQLObjectType({ name: 'Cl ...

Creating interactive <td> elements in HTML with JavaScript editor capabilities

Currently, I am working on creating an editable table feature and managed to find a good example to follow. However, I have encountered some issues along the way. <td contenteditable="true" class="hover" onBlur="saveToDatabase(this,'question' ...

Using Angular's ng-switch directive within a select dropdown option

Can we implement the [Data Presentation Format] to be utilized in the [Dropdown Box]? Specifically, I would like the "parent" items to appear as is within the dropdown, while the "child" items should have a [tab] indentation to denote their relationship wi ...

Exploring the possibilities of custom query pagination and Ajax in Wordpress

My Wordpress website has custom category and single pages with a unique query. The pagination is set up to load posts on the same page, which works fine on the homepage. The issue arises when trying to use pagination in single pages and categories using & ...

Refreshing the v-model in a child component

Within my parent component, the code structure is similar to this: <template> <ProductCounter v-model="formData.productCount" label="product count" /> </template> <script setup> const initialFormData = { ...

Failed Attempt to Execute React Native Application using Command Prompt (iOS)

I'm currently working through the React Native tutorial found on their official website. During my project building process, I utilized the following command: react-native run-ios An error was encountered: Found Xcode project TestProject.xcodeproj ...

Personalized modify and remove elements on a row of the DataGrid material-ui version 5 component when hovered over

In my React Js app, I am utilizing Material UI components or MUI v5 as the UI library for my project. Within the DataGrid/DataGridPro component, I am implementing a custom edit and delete row feature. The requirement is to display edit and delete icons w ...

"Utilize binding in ReactJS to maintain the correct context

I'm currently learning how to update states in ReactJS by following a tutorial. In the tutorial, I came across this line of code: this.updateLanguage = this.updateLanguage.bind(this). Although I grasp the basics of 'this' and 'bind&apos ...

Verify role declarations and display components if valid

I am currently developing an application using Angular on the front-end and ASP.NET on the back-end. Within this application, there are two roles: user and admin. I have implemented a navigation bar with several buttons that I need to hide based on the use ...

Scrolling horizontally in a container using the mouse wheel

Is there a way to enable horizontal scrolling in a div using the mouse wheel or drag functionality with jQuery? I attempted using draggable, but it did not work effectively in my specific code scenario. Currently, I have a horizontal scrollbar. Are there ...

Providing secure access to Apostrophe-CMS S3 assets and attachments via HTTPS

Currently, I am utilizing Amazon S3 to deliver both my static assets and user uploads within the context of apostrophe-cms. While my site is loading via https, all of my assets appear to be loading using http. I have set up a cloudfront distribution at th ...

Unable to execute an Angular 2 application within Visual Studio 2015

I encountered an error while trying to set up an environment on VS 2015 with Angular2. Whenever I run the command "npm start," I receive the following error message. I attempted using "npm cache clean --force" before running "npm start," but the error pers ...