I've got a list item with a field of type URL. As you know, an URL-field consists of two parts: a description and a URL.

Using javascript to update a field that consists of one part is easy, you just do something like

 myItem.set_item('MyTextField', 'MyValue');

But how do I update a URL-field that way? I've tried the following

var URLObj = { URL: 'http://myurl', Description:'this is a description' }; 
myItem.set_item('MyURLField', URLObj);

but it fails during set_item,

Also tried this:

    var URLField = myItem.get_item('MyURLField');
URLField.set_description('this is a description');

But get_item only returns null.

The URL-field I'm trying to set is initially empty, so that's probobly causing some problems, seems like getting empty fields don't return anything ,just null.

So any ideas on what I could try?


MSDN says that when assign a value to a list item field you must provide a string, but its not true for complicated fields such url or others. You must use this approach:

var fvalue = new SP.FieldUrlValue();
fvalue.set_description("my description");
newListItem.set_item("linkfield", fvalue);

Useful resource about CSOM javascript classes here

Your Answer

