Domanda

I create a new page with javascript csom. I am able to give it a title, byline, content etc., but it won't accept an image reference. It doesn't give me any error messages, nor reaching my error function, but I'm obviously missing something here as the new page does not have any images attached.

Any ideas on how to do this?

Here is my code:

var pageInfo = new SP.Publishing.PublishingPageInformation();
var newPage = pubWeb.addPublishingPage(pageInfo);
context.load(newPage);

context.executeQueryAsync(function () {

    var listItem = newPage.get_listItem();
    context.load(listItem);

    context.executeQueryAsync(function () {

        var title = $('#head').val();
        listItem.set_item('Title', title);

        listItem.set_item('PublishingPageImage', { "Url": "/sites/intranett/PublishingImages/ExampleImage.png", "Description": "testing" });

        listItem.update();

        context.executeQueryAsync(function () { }, onFailedCallback);

    }, onFailedCallback);
 }, onFailedCallback);
È stato utile?

Soluzione

I needed to include the html image tag when setting the PublishingPageImage property.

listItem.set_item('PublishingPageImage',  "<img alt='image' src='/sites/intranett/PublishingImages/ExampleImage'>"); 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top