1

I'm using sp.js and I'm confused, how to update property of property? For example I have:

Item: { 
    Title, 
    Image: { 
        Url: 'xxx', 
        Description: 'xxx' 
    }
} 

I've tried .load(Item) and then image = Item.get_item('Image') but image.set_item('Url', 'smthnew') and .update() fails...

How to actually update Image.Url via .update()?

Thanks a lot!

1
  • show your whole code block Commented May 12, 2017 at 17:17

1 Answer 1

1

Looks like this is Hyperlink or picture column.

To update it using JSOM, try the below code:

var clientContext  = new SP.ClientContext();          
var web = clientContext.get_web();          
var lists = web.get_lists();     
var oList = lists.getByTitle("TestList");     
oListItem = oList.getItemById(1);     
var urlValue = new SP.FieldUrlValue();
urlValue.set_url("https://www.google.co.in");
urlValue.set_description("custom image description");
oListItem.set_item("Image", urlValue);     
oListItem.update(); 
clientContext.load(oListItem);
clientContext.executeQueryAsync(function(){
        console.log("success");
    }, function(){
        console.log("error");
});  
3
  • Yes, looks valid, gonna try. Truly it is right. So each time I face some complex property I should find reflection of it in some sp object? Like URL object for this kind of field. Thanks Commented May 12, 2017 at 18:16
  • Glad i could help ! Please consider marking it as answer :) Also, you can can follow this link Update list items using JSOM Commented May 12, 2017 at 18:23
  • Well, at least now I know it's called JSOM -_- Commented May 12, 2017 at 18:24

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.