Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Update Site Title using JavaScript Client Side Object Model: The property or field "Title" has not been initialized."

$
0
0

Hi all,

I am using the JavaScript Client Side Object Model to try to update the site title to the value of the current site title and append the word "Archived". I can set the title to a text value, but I need to get the current title (get_title) first so I can append it. When I try the following, it states:

"The property or field "Title" has not been initialized."

The failure happens on this line:

var currentTitle = this.oWebsite.get_title(); 

I need to get the current title of the site, so I can update it to include the word "Archived". Here is my code. Thanks in advance!

Kelly

    $(function() {
        // Make sure the SharePoint script file 'sp.js' is loaded before your
        // code runs.
        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
    });

// Create an instance of the current context.
function sharePointReady() {
    var clientContext = new SP.ClientContext.get_current();
    this.oWebsite = clientContext.get_web();
    
    var currentTitle = this.oWebsite.get_title();

    this.oWebsite.set_title(currentTitle + 'Archived');
    this.oWebsite.set_description('This is an archived Web site.');
    this.oWebsite.update();

    clientContext.load(this.oWebsite, 'Title', 'Description');

    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded), 
        Function.createDelegate(this, this.onQueryFailed)
    );
}

function onQuerySucceeded(sender, args) {
    alert('Title: ' + this.oWebsite.get_title() + 
        ' Description: ' + this.oWebsite.get_description());
}
function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
}

 

 


Personal Blog: http://thebitsthatbyte.com



Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>