After doing a lot of research on REST, I'm stuck. Any help would be appreciated. I want to users to be able to update the status of a Task by clicking a button which takes them to a url.
- The column is a choice column, and it's called formStatus, with (3) choices (Ongoing, Completed, and Cancelled)
- The url is to a Site Page called '../../sitepages/taskslanding.aspx', and the script lives on that site page in the content editor
- I've named the scrip 'jsomJs.js', which is below:
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function()
{
var query = window.location.search.substring(1);
var vars = query.split("=");
var itemId = vars[1];
var ctx = new SP.ClientContext.get_current();
var customList = ctx.get_web().get_lists().getByTitle('Tasks');
var listItem = customList.getItemById(itemId);
listItem.set_item('formStatus', 'Completed');
listItem.update();
ctx.executeQueryAsync(
function(){ alert('Item updated'); },
function(sender, args){ alert('Error: ' + args.get_message()); }
);
});
I created a url for each list item, when clicked, fired the following (I'm using Task ID=5 just as an example)
<a href="../../sitepages/taskslanding.aspx?ID=5>Approve This Task</a>
UPDATE 2/6/19
For whatever reason, this code ONLY works on Task (ID #103). When entering the url ../../tasklanding.aspx?ID=103, this code works as expected.
My Task IDs start at #33 and end on #945, wo #103 isn't even the earliest task! May I add that this code does NOT work on Task #100, #101, #102, #104, etc. Any one have ANY idea how to fix this? Or why it is happening?
taskslanding.aspxpage than your script. Is that page checked out? Is there some other web part on that page that's trying to do something?../../SitePages/taskslanding.aspxhas (1) content editor on the page, which points to the Site Assets library js file containing the EXACT code in the original question. ID# 870 exists, and I am confused as to what isn't working. Do I need to reference the list name (Tasks) in the query string? Are we certain that I can run this script from a Site Page?jsfile from a CEWP. You're doing that using the Content Link property? If so, what I would do is this: create an HTML file that hasscripttags that link to yourjsfile, and pull in the HTML file using the CEWP Content Link. See this other answer where I am kind of explaining the same thing. You definitely should be able to run that code on a site page, it seems like it's not getting loaded on to the page correctly.