0

I want to insert a image from another media resource. This will be uploaded into the site assets folder (or a defined one).

These selection will be made in a app part, that will be opened up in a modal dialog. After the dialog closes, it returns the url, where the image is stored like

"http://spdomain/siteassets/myimage.png". 

Now I would store these image into the PublishingFieldImage Column, the best case is, that it will be done in JavaScript.

Is that possible? Or is there another solution (instead of programming a core solution that works with C#)?

1

Publishing Image field accepts the value in the following format:

<img src='{imageurl}'>

The following example demonstrates how to set Publishing Image field value via JSOM.

var listTitle = 'Pages';
var itemId = 1;
var fieldName = 'PublishingRollupImage';
var imageUrl = '/PublishingImages/NewsDetails.png';
var fieldValue = String.format("<img src='{0}'  >",imageUrl);

updateListItem(listTitle,itemId,fieldName,fieldValue, 
   function(){
       console.log('List item has been updated');
   },
   function(sendera,args){
       console.log(args.get_message());
   });

where

function updateListItem(listTitle,itemId,fieldName,fieldValue,success,error)
{
   var ctx = SP.ClientContext.get_current();
   var list = ctx.get_web().get_lists().getByTitle(listTitle);
   var item = list.getItemById(itemId);
   item.set_item(fieldName, fieldValue);
   item.update();
   ctx.executeQueryAsync(
      function() {
            success();
      },
      error);
}

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.