4

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);
  • Make sure the URL is ok ? (in your example you have "intranett" with 2 't' ... that could be a typo in the example code, or not... Just want to make sure ^^) – AymKdn Apr 10 '13 at 13:38
  • Actually "intranett" is correct here, but thanks :) – user1942910 Apr 11 '13 at 17:25

1 Answers1

1

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'>");