Tuesday, August 8, 2017

How To CheckIn And CheckOut a SharePoint page using JavaScript(JSOM)

Hi Friends,

Recently I have come across a requirement where I need to update the properties of a Sharepoint page. In this post we are going to see how to checkin and checkout a page in sharepoint using JSOM.
Below are the code snippets.

CheckOut:
function checkOut(){
        var ctx = SP.ClientContext.get_current();
        var page = ctx.get_web().getFileByServerRelativeUrl(window.location.pathname);
        //you can use any path. Here I am using current page.
        page.checkOut();
        ctx.load(page);
        ctx.executeQueryAsync(Function.createDelegate(this, checkOut_Success),
                                            Function.createDelegate(this, checkOut_Fail));
}
function checkOut_Success(sender, args){
 alert("Checked Out");
//do your actions
}
function checkOut_Fail(sender, args){
   alert("Fail checkout");
}

CheckIn:
function checkIn(){
         var ctx = SP.ClientContext.get_current();
        var web = ctx.get_web();
        var page = web.getFileByServerRelativeUrl(window.location.pathname);   
        //you can use any path. Here I am using current page.  
        page.checkIn();
        page.publish();
        ctx.executeQueryAsync(Function.createDelegate(this, checkIn_Success),
                                            Function.createDelegate(this, checkIn_Fail));
}
function checkIn_Success(sender, args){       
    alert(" checked in "); 
}
function checkIn_Fail(sender, args){   
    alert("Fail  checked in "+args.message);
}

Hope this helps...

Monday, August 7, 2017

How to Copy/Move a SharePoint Page/File from one location to another using Javascript

Hi Friends,

In this blog we are going to see How to copy or move a sharepoint Page/File from one location to the other using Javascript.

By default SP.js in SharePoint provides the following functions through which we can perform this activity with the minimal coding effort.

SP.MoveCopyUtil.copyFile
SP.MoveCopyUtil.moveFile

Copy a Sharepoint File/Page:
In the below code snippet we are copying the home.aspx present in pages library to the Folder called "duplicate" under the same pages library.

In order to achieve it, we will be using the function SP.MoveCopyUtil.copyFile which expects the below parameters

1)Current context
2)Source url – Full url of the file/page.
3)Destination url – Full destination url of the file/Page.

Code snippet:
var current_context = SP.ClientContext.get_current();
SP.MoveCopyUtil.copyFile(current_context,"https://siteurl/pages/home.aspx","http://siteurl/Pages/duplicate/home.aspx");
current_context.executeQueryAsync(function(){ PageCopySuccess(); },function(){ PageCopyFailure(); });

function PageCopySuccess(){
alert('Success');
}

function PageCopyFailure(){
alert('Failed');
}


Move a Sharepoint File/Page:
In the below code snippet we are moving the home.aspx present in pages library to the sitepages page library.

In order to achieve it, we will be using the function SP.MoveCopyUtil.moveFile which expects the below parameters

1)Current context
2)Source url – Full url of the file/page.
3)Destination url – Full destination url of the file/Page.

Code snippet:
var current_context = SP.ClientContext.get_current();
SP.MoveCopyUtil.moveFile(current_context,"https://siteurl/pages/home.aspx","http://siteurl/sitepages/home.aspx");
current_context.executeQueryAsync(function(){ PageMoveSuccess(); },function(){ PageMoveFailure(); });

function PageMoveSuccess(){
alert('Success');
}

function PageMoveFailure(){
alert('Failed');
}

Hope this helps...


Thursday, March 23, 2017

Structural Navigation vs Managed Navigation in SharePoint

Hi Friends,

In this post we are going to learn about the navigation options present in SharePoint Online.

Below are the two main out of the box navigation options in SharePoint
1) Structured Navigation
2) Managed Navigation

What is Structured Navigation?
This is SharePoint out of the box navigation used by default and it is based on the site structure we define for our portal.

Below are some of the advantages and disadvantages using Structured Navigation.
PROS
CONS
  • Navigation will be updated automatically whenever Sites are added.
  • Easy to configure.
  • Pages are automatically added.
  • Security trimmed, so if a user doesn’t have access to a link it will not appear in the top navigation.

  • Slower performance with complex navigation structure having more than 10 levels.
  • URLs are not friendly and can be hard to memorize.
  • Homepages belonging to structured navigation links do not appear in search when you type a search term.
  • Cannot tag a structured navigation link to a document that it may relate to.


What is a Managed Metadata Navigation?
Managed Metadata is a hierarchical collection of centrally managed terms that we can define, and then use as attributes. It uses a dedicated term set for site navigation and the terms correspond to the friendly URL segment created.

Below are some of the advantages and disadvantages using Managed Navigation
PROS
CONS
  • Easy to maintain.
  • Significantly faster page loads.
  • Pages with term show up in search results.
  • Documents tagged with navigation term show up in search results along with homepage of term.
  • Friendly URLs that are easy to remember.
  • Easy to maintain with more options to target search.
  • Pages are automatically added.

  • Not security trimmed, so if a user doesn’t have access to a link in the top navigation they will still see it but can’t get to it.
  • Sites are not automatically added.
  • Cannot be used across site collections.


Hope this helps...

Popular Posts