1

I am trying to create a button on the Display Page where it will update a value (Open, Close, Cancel), either redirecting them back to the Display Page or just taking them back to the List Page.

They want the button so I have to create a button (sigh).

When I click the button, when it gets to the clientContext line (set as variable oList), it states that 404 error, file not found. Its based on the siteURL (which I think is causing the problem).

Here is the code (I got this from MSDN. See link at end of post):

<input type="button" value="Close Testing" onclick="updateListItem();" />
<script>
var siteUrl ="Lists/ListWithAlotOfCrap";
var urlParam=GetUrlKeyValue("ID");
function updateListItem() {
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle("RiskMgmt");
    this.oListItem = oList.getItemById(urlParam);
    oListItem.set_item("State", "Close");
    oListItem.update();
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {

    alert("Item updated!");
}

function onQueryFailed(sender, args) {

    alert("Request failed. " + args.get_message() + "\n" + args.get_stackTrace());
}
</script>

Any Suggestions?

Here's the source link: How to update a list Item value on a button click using a javascript or Jquery SharePoint Desiginer 2010

1 Answer 1

2

In updateListItem() function:

Use var clientContext = new SP.ClientContext.get_current();

instead of var clientContext = new SP.ClientContext(siteUrl);.

Also, make sure that you are passing display name(Not the name in URL) of list in following line:

var oList = clientContext.get_web().get_lists().getByTitle("RiskMgmt");
2
  • Thanks @ganesh-sanap. As far as the var oList variable, isn't it the name of the List? And use the List name? Also, the clientContext is showing as [object object], not sure if anything is being passed at the clientContext.
    – adams-j
    May 9, 2019 at 14:55
  • Disregard @ganesh-sanap. It worked! I had to change the List Name from Production to Dev...worked beautifully! I'm marking this as an answer! many thanks!
    – adams-j
    May 9, 2019 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.