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'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');
myItem.update();

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_url('http://myurl');
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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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_url("http://google.com");
fvalue.set_description("my description");
newListItem.set_item("linkfield", fvalue);

Useful resource about CSOM javascript classes here

share|improve this answer
    
Works fine. Can't believe I missed this. Thanks! –  Drkawashima Apr 17 '12 at 9:53

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.