Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Thursday, August 3, 2017

Anonymous Access for Client Object Model in SharePoint

Have you ever faced this error failed Message: The method “GetItems” of the type “List” with ID {GUID} is blocked by administrator on the server.on public facing site ?

So apparently anonymous users, using the Client Object Model, are blocked from using

    GetItems and GetChanges on SPLists
    GetChanges and GetSubwebsForCurrentUser on SPWebs
    GetChanges on SPSites

The good news, however, is that the ClientCallableSettings value can be adjusted to allow anonymous user access to one or more of these methods.
Doing this with PowerShell:
$webapp = Get-SPWebApplication "http://sp2013dev"
$webapp.ClientCallableSettings.AnonymousRestrictedTypes.Remove([microsoft.sharepoint.splist], "GetItems")
$webapp.Update()
Be sure to replace "http://sp2013dev" with whatever url your target webapp has. After doing this, anonymous calls to GetItems will work for that web application. The changes are persisted in the SharePoint database, and last until you change the setting again, or recreate the web application.

Thursday, July 23, 2015

JavaScript Function: HTML Encode for Multiple Lines Of Text Sharepoint

Recently I have found the need to HTML Encode text in JavaScript, especially when using update list items and Single Line Of Text or Multiple Lines Of Text fields.
An easy way to do this is use the native functionality of the browser when it processes DIV’s.
Any text inside of a DIV automatically gets HTML Encoded.  So all we have to do is create a DIV on the fly, insert the text and return the output.
1 function HTMLEncode(str) { 2 var div = document.createElement('div'); 3 var text = document.createTextNode(str); 4 div.appendChild(text); 5 return div.innerHTML; 6 }