Tuesday, August 20, 2013

Remove an user from item level permissions using JSON.

To delete a user from item level permissions using JSOM , use the following code.

var oUser= clientContext.get_web().ensureUser('your name@yourcompany.com');
oListItem.get_roleAssignments().getByPrincipal(oUser).deleteObject(); // oListItem- List item reference.


Happy coding !!!

Wednesday, August 7, 2013

All In One Script Framework

All in one script framework has many sample power shell scripts for automation which are scenario focused. It has sample scripts for Office, Office 365, SharePoint, SQL Server, Exchange and Lync.

Please visit the site , you can request for scripts, provide feedback as well.

Tuesday, July 30, 2013

JSOM Intellisense in VisualStudio

It should be very easy for you to reference the following piece of comment, will show you intellisense in Visual Studio 2010 and above to work with SharePoint  Client applications using JSOM. If you are developing SharePoint Client applications, make sure you have installed SharePoint client SDK as described in my earlier posts or working locally on a machine in which SharePoint is installed.

Add a new *.JS file to the project, make a reference as given in the picture, and make sure the path to the SharePoint JavaScript file is right.


Assigning Item Level permission using JSOM in Sharepoint 2013

This post contains the code to assign Item level permission using JSOM. 

function assignItemLevelPermission()
                var clientContext = new SP.ClientContext.get_current();
                var collRoleDefinitionBinding;
                var objListItem="your list item"
                collRoleDefinitionBinding = SP.RoleDefinitionBindingCollection.newObject(clientContext);
                 // Make sure you pass on the user identity as you@youroffice.com
                 var oUser= clientContext.get_web().ensureUser(“you@youroffice.com”);                
                objListItem.get_roleAssignments().add(oUser, collRoleDefinitionBinding);
                                                                function onQuerySucceeded() {
                                                                function onQueryFailed() {


Monday, July 29, 2013

Create a DocumentSet(Predefined) using JSOM in SharePoint 2013 (on-premise/on-line).

This post explains how we can create a documentset(predefined) in a folder using JSOM. As in my previous post  you can apply a technical solution which can be remote/local. This solution can be applied for on-premise and as well as SharePoint on-line.

There might be business cases like you have to create a set of documents when you create a project. Assuming this business scenario, I have created a SharePoint List called ProjectMgmt and a document library called ProjectLibrary. I have configured the documentset content type with some predefined documents.

I have created a new form for the ProjectMgmt list and in that I have added the following code. I have commented out the default SharePoint Save button and included an HTML input button and named it as “Save”.

<input type="button" value="Save"  id="CreateDocumentSet" name="bCreateDocumentSet" onclick="javacript:CreateFolder();" />

Under the content place holder - placeholder main I have referenced the following scripts
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/SP.DocumentManagement.js"></script>
<script type="text/javascript" src="/layouts/15/app.js"></script>
<script type="text/javascript"src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

The code below, is to create a folder and then the document set inside the folder. I have left out the JSOM code for creating an item in a SharePoint list which is available here.  I have to create a folder with the project name and prefix the project name for the document set. You could see that I have used the documentset content type id "0x0120D520" to create the document set.

<script type="text/javascript">                
                var clientContext;
                var ProjectName;
                var ProjectID;   
                var folderUrl;
                Function name :CreateFolder
                Parameters      : context , arguments
    Description      : This function is responsible for the creation of the folder. 
                           On success calls the onQuerySucceededCreateDocumentSet.          
                Returns           : None
                function CreateFolder(sender, args)
                      clientContext = new SP.ClientContext.get_current();
                      oList = clientContext.get_web().get_lists().getByTitle('ProjectLibrary');                                  
                       //Acquire the values entered by the user
                       ProjectID =$("input[title='ProjectID']").val();

                       var web = clientContext.get_web();
                       var newDocSetName =$("input[title='ProjectName']").val();
                       var list = web.get_lists().getByTitle('ProjectLibrary');
                       itemCreateInfo = new SP.ListItemCreationInformation();
                       //Create the folder
                       itemCreateInfo.set_underlyingObjectType                                                     (SP.FileSystemObjectType.folder);
                       this.oListItem = list.addItem(itemCreateInfo);
                                    Function.createDelegate(this,                                                  this.onQuerySucceededCreateDocumentSet),
                                    Function.createDelegate(this,                                          this.onQueryFailedFolderCreation)

                function onQueryFailedFolderCreation(sender, args)
                                alert('Folder Creation Failed due to the error: ' + args.get_message());

                Function name                   : onQuerySucceededCreateDocumentSet
                Parameters                        : context
                Description                        : This function is responsible for the creation of the Document Set
                Returns                              : None
                function onQuerySucceededCreateDocumentSet(param)
                {              var docSetContentTypeID = "0x0120D520";
                                clientContext = new SP.ClientContext.get_current();
                                var web = clientContext.get_web();      

                                folderUrl = “YOUR SITE URL” + “/YOUR DOCUMENT LIBRARY/"

                                var folder= web.getFolderByServerRelativeUrl(folderUrl);
                                var newDocSetName =ProjectName + '-Documentset';
                                var docsetContentType = web.get_contentTypes().getById(docSetContentTypeID);     
                                                function ()
                                                                //Create the document set.
var isCreated = SP.DocumentSet.DocumentSet.create(clientContext, folder , newDocSetName,                                                               docsetContentType.get_id());  
                                                 function onQuerySucceededDocumentSetCreated()
                                                        alert('DocumentSet has been Created');
                                                  function onQueryFailedDocumentSetCreation(sender, args)
                                                          alert('Document Set Creation Failed due to the error: ' +                                                                                           args.get_message());


                                                function ()
                                                                alert('Folder loading failed');


This code works in SharePoint 2013 on-premises and also on SharePoint 2013 on-line. Happy coding!!!

Friday, July 26, 2013

Develop Client Applications for SharePoint 2013 using Client Components SDK.

You can develop Client applications which can perform basic operations with SharePoint 2013.

Suppose if you are developing a Silver light application or a JavaScript application which performs basic operations on SharePoint, you do not require a SharePoint foundation 2013 or SharePoint server 2013 to develop.  You can download the “SharePoint Server 2013 Client Components SDK” from here  and reference the installed assemblies,scripts for  remote/local development. 

You can host it remotely on a machine which has the aforementioned SDK/Redistributables and do basic operations on SharePoint 2013.

The supported operating systems are windows 7, windows 8 release preview, windows server 2008 RC. Choose the 32 bit/ 64 bit installable according to the operating system which you are using. The package installs all files in:
%ProgramFiles%\SharePoint Client Components\Assemblies
%ProgramFiles%\SharePoint Client Components\Scripts

The following files in %ProgramFiles%\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI:

The following files in %ProgramFiles%\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\ClientBin:

The following files in %ProgramFiles%\Common Files\Microsoft Shared\Web Server Extensions\15\Client:

If installing 64-bit version of the msi:

The following files in %ProgramFiles(x86)%\Common Files\Microsoft Shared\Web Server Extensions\15\Client:

Please  let me know if this information is right and useful  !!! 

Reference : http://msdn.microsoft.com/en-us/library/fp179912.aspx.