thisisanemergency
thisisanemergency

Reputation: 1

Use site title as default value in text or calculated field

I would like to set up a site column that will by default show the site title. This should be done by either setting the default value of a single line of text field or using a calculated field. I will use the field value in workflows. I have tried using [Site Name] and [Site Title] but this produces an error. Is there an identifier or lookup I can use to retrieve this property? I'm using SharePoint 2010 and SPD 2010.

Upvotes: 0

Views: 3120

Answers (1)

Yannic DoNot Text
Yannic DoNot Text

Reputation: 63

I think thats not possible with standard functionality. But you can achieve your goal with the SPD.

First edit your masterpage and include a new script tag for jQuery inside the head tag. I would recommend to upload the current version to a document library e.g. style library.

<script type="text/javascript" src="/_layouts/scripts/jquery.min.js"></script>

Now add this script also to the masterpage:

<script type="text/javascript">
var web = null;

$(document).ready(function () {
    ExecuteOrDelayUntilScriptLoaded(initialize, "sp.js");       
});

function initialize() {
    if ($("input[title='CurrentSiteTitle']").length > 0) {
        var context = new SP.ClientContext.get_current();
        web = context.get_web();
        context.load(web);
        context.executeQueryAsync(onSuccess, onFail);
    }
}

function onSuccess() {
    $("input[title='CurrentSiteTitle']").val(web.get_title());
}
</script>

Add a new site column and name it fancy like 'CurrentSiteTitle' (single line of text). For some reason I couldn't make it work with the Id.

Upvotes: 0

Related Questions