Question

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

Était-ce utile?

La solution

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");
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top