Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a list .

I want update special item of it with javascript.

I created a js file and add this code to it :

 var context = new SP.ClientContext.get_current();
 var web = context.get_web();
 var list = web.get_lists().getByTitle("Sends");
 var salesItem = list.getItemById(90);
 salesItem.set_item("Status", "Closed");
 salesItem.update();

It is work for text field but don't work for Choice field.

How do update a item with javascript?

share|improve this question
add comment

3 Answers

Hi for update list item using ECMA script you have to use SP.js

in your code i don't see SP.js reference

use this code i am update task list status column which is choice field

ExecuteOrDelayUntilScriptLoaded(updateProduct, "SP.js"); 
function updateProduct() {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle("Tasks");
var product = list.getItemById(1);
product.set_item("Status", "Completed");
product.update();
context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}

function success()
{
alert('Done');
}
function failed()
{
 alert('problem');
}
share|improve this answer
    
my code is like this. for example:When i use my code for 'Title' it is work, but when i use for choice filed don't work. –  ar.gorgin Aug 28 '12 at 5:43
    
dear i update my choice field... U see it's status field of task list ....Please make sure u enter value of choice is in list otherwise it not accept..Thanks –  Vishal_Sharepoint Aug 28 '12 at 5:46
    
also u see the alert??? "Done" or "Problem"?? –  Vishal_Sharepoint Aug 28 '12 at 5:47
    
Yes, 'Closed' is a item of choice field. When i run, get "Done". –  ar.gorgin Aug 28 '12 at 5:57
    
I delete column then add again, now when i update a item it set defualt value for chioce column :( –  ar.gorgin Aug 28 '12 at 7:29
add comment

Have you verified the Internal name of the Status field is "Status". I think the Internal Field Name is specified wrong in the code.

share|improve this answer
    
No, i use Internal Name. –  ar.gorgin Aug 28 '12 at 5:58
add comment

Please try these things:

  1. Validate Internal Name of the column that is used
  2. Validate the choice values of the column. sometimes there might be spaces before or after the values.
  3. Use a success function and check the error message that is returned after the async query.

Hope this helps you!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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