3

I have a list named Department in which list item has a IconImage column which has publishingImage type. default this field is set to nothing and I want to update that field with image URL using rest.

Can anybody please help me?

I am able to retrieve that field data using FieldValueAsHtml but not able to update that field.

  • Thank you Rafael. Will try this and let u know if find any issue. – Mukesh Singh Feb 7 '17 at 3:54
2

Its not possible to update using REST, you can try below JSOM code to update its value:

1) Either when you have ID

function updatePublishingImage() {

    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Pages');

    var oListItem = oList.getItemById(1);

    oListItem.set_item('PublishingPageImage',  "<img alt='abc image' src='/sites/test/PublishingImages/abc.jpg'>"); 

    oListItem.update();

    clientContext.executeQueryAsync(function(){
    console.log("updated image");
    },function(){
    console.log("something went wrong");
    });
}

2) Or when you know the server relative url:

var ctx = SP.ClientContext.get_current(); 
var file = ctx.get_web().getFileByServerRelativeUrl(url);   
ctx.load(file,'ListItemAllFields'); 

ctx.executeQueryAsync(
      function (file) {
    var listItem = file.get_listItemAllFields(); 
        listItem.set_item("PublishingPageImage","<img alt='abc image' src='/sites/test/PublishingImages/abc.jpg'>");    
    listItem.update();
        ctx.executeQueryAsync(
          function () {
        },function(){
       });
}, function(){
      });
1

I believe that you can only update the publishing image field using CSOM or JSOM. Let me know if you need an example code of updating the publishing image field using JSOM.

  • Please share the example as it will be required to complete the answer – Arsalan Adam Khatri Feb 6 '17 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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