Friday, November 27, 2015

Monday, November 23, 2015

Update date friendly format for all lists in a site collection

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$site= Get-SPWeb "SITEURL"
$ColumnName ="Modified"
foreach ($web in $site.Site.AllWebs)
{
    Write-Host "Updating Site: " $web.Title
    for ($i=0; $i -lt $web.lists.count; $i++)
    {
        $list = $web.lists[$i]
        Write-Host $List.Title
        if($list.fields.ContainsField($ColumnName))
        {
            $column = $list.Fields[$ColumnName]
            $column.FriendlyDisplayFormat = [Microsoft.SharePoint.SPDateTimeFieldFriendlyFormatType]::Disabled
            $column.Update()
            Write-Host "Field type updated on: $($list.Title)"
        }
    }
    $web.Dispose();
}

Wednesday, November 18, 2015

Promise to overcome async

promise = new Promise(function(resolve, reject) {
     var ctxr = new SP.ClientContext(siteUrl);
     var oList = ctxr.get_web().get_lists().getByTitle('LISTNAME');
     var camlQuery = new SP.CamlQuery();
     .
     .
     .
     ctxr.executeQueryAsync(onQuerySucceeded, onQueryFailed);
});

Tuesday, November 17, 2015

Using client people picker

 initializePeoplePicker('<peoplePickerDivId>', "");

People picker values can be read by

        var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv1_TopSpan;
        var users = peoplePicker.GetAllUserInfo();
        var usersArr = new Array();
        var userInfo = '';
        for (var i = 0; i < users.length; i++) {
            usersArr.push(SP.FieldUserValue.fromUser(users[i].Key));
            alert(SP.FieldUserValue.fromUser(users[i].Key).get_lookupValue());
        }

function initializePeoplePicker(peoplePickerElementId, strUser) {
    var schema = {};
    schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
    schema['SearchPrincipalSource'] = 15;
    schema['ResolvePrincipalSource'] = 15;
    schema['AllowMultipleValues'] = true;
    schema['MaximumEntitySuggestions'] = 50;
    schema['Width'] = '280px';
    if (strUser != "") {
        this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
        var peoplePicker = eval("this.SPClientPeoplePicker.SPClientPeoplePickerDict." + peoplePickerElementId + "_TopSpan");
        peoplePicker.AddUserKeys(strUser);
    } else {
        this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
    }
}

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...