Tuesday, February 17, 2015

Set Default Look up value for Look up column SharePoint 2010 list

 Copy and paste the following script.<script language="ecmascript" type="text/ecmascript"> 
        var fieldCollection;
        var field;
        var list;
        function fieldDefaultValue() {
            var clientContext = SP.ClientContext.get_current();
            if (clientContext != undefined && clientContext != null) {
                var webSite = clientContext.get_web();
                this.list = webSite.get_lists().getByTitle("List Request");
                this.fieldCollection = list.get_fields();
                this.field = fieldCollection.getByTitle("Description");
                this
.field.set_defaultValue("Default");                this.field.update();                clientContext.load(this.field);
                clientContext.executeQueryAsync(Function.createDelegate(thisthis.OnLoadSuccess),
Function.createDelegate(thisthis.OnLoadFailed));
            }
        } 
        function OnLoadSuccess(sender, args) {
            
alert(this.field.get_defaultValue());        } 
        function OnLoadFailed(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        }
</
script
>    <input id="btnFieldDefaultValue" onclick="fieldDefaultValue()" type="button" value="Field Default Value" />

1 comment: