Tuesday, February 3, 2015

SharePoint 2013 Hosting Tutorial - How to Export and Import using JSON and REST in App in SharePoint ?


One massive request from IT Managers and workplace 365 SharePoint website is regarding Migrations of data and SharePoint Objects from SharePoint site, yes there's lots of tools that assist you creating this kind of migration,we hear lots regarding moving users, Lists, Content sorts but how this really works. Now, this example will show how you can use the data in JSON base from REST operations & SharePoint Objects from SharePoint Sites then change it and import to different SharePoint sites .

The made Sharepoint App model indicates how we can export and import Sharepoint Objects utilizing JSON and REST with Javascript. This sort of technique can be exceptionally valuable to move Sharepoint Site Configurations to numerous sites destinations, for this case utilized the "RoleDefinition" object to export a existing RoleDefinition Object and import with a different name using JSON data.

How the App Works?

The application get a current RoleDefinition authorization Name in the Sharepoint site and make a REST operation to give back where its due information related.

The main thing was get the Name of a consent in Permission Levels, you can get to the page emulating the Top Right Menu Site settings > Site Permissions > Ribbon Permissions Levels.

Export JSON Roledefinition

At the point when the Permission name is chosen access to Exportimport App and select the Option Export RoleDefinition JSON and the JSON information is shown in the Textarea.


function ExportJson() {
var executor = new SP.RequestExecutor(SPAppWebUrl);
executor.executeAsync({
url: SPAppWebUrl + "/_api/SP.AppContextSite(@target)/Web/Roledefinitions?$filter=Name eq '" + $('#Roledefinition').val() + "'&@target='" + SPHostUrl + "'",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) { $('#ExportJSON ').val(data.body); SP.UI.Notify.addNotification('Roledefinitions exported with Success!!', false); },
error: function (sender, args) {
SP.UI.Notify.addNotification('Request failed. ' + sender.statusText + '\n' + sender.statusCode); }
});
}

Import JSON Roledefinition

Duplicate the JSON data and paste in the Import JSON TextArea and give another Name to the Roledefinition and select "Import new Roledefinition JSON". This operation will send a POST Method by REST with the JSON information and properties related in the Body of the message to Sharepoint.

After this the object ought to be made with achievement.


And here is the code:
function ImportJson() {
var item = JSON.parse($('#ImportJSON').val()).d;
var executor = new SP.RequestExecutor(SPAppWebUrl);
if (item.results.length == 1) {
executor.executeAsync({
url: SPAppWebUrl + "/_api/SP.AppContextSite(@target)/web/roleDefinitions?@target='" + SPHostUrl + "'",
method: "POST",
body: "{ '__metadata': { 'type': 'SP.RoleDefinition' }, 'BasePermissions':{ '__metadata': { 'type': 'SP.BasePermissions' }, 'High': '" + item.results[0].BasePermissions.High + "','Low':'" + item.results[0].BasePermissions.Low + "'}, 'Description': '" + item.results[0].Description + "', 'Name': '" + $('#NameRoledefinition').val() + "', 'Order': " + item.results[0].Order + " }'",
headers: {
"content-type": "application/json; odata=verbose"
},
success: function (data) { SP.UI.Notify.addNotification('New role "' + $('#NameRoledefinition').val() + '" Roledefinitions imported with Success!!'); },
error: function (sender, args) {
SP.UI.Notify.addNotification('Request failed. ' + sender.statusText + '\n' + sender.statusCode);
}
});
} else {
SP.UI.Notify.addNotification('More than 1 item', false);
}
}


After the achievement Message from the last operation, you can refresh the Permission Level Page and accept if the new Roledefinition was made with sucess.

SharePoint 2013 Hosting Recommendation

HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation option.
Tags: , , , ,

Written by

We've been a trustworthy web hosting review site, and have reviewed 350+ web hosts since 2008 - focusing on helping developers, bloggers, freelancers and small business owners to pick up the right web host based on the budget and requirement, including shared web hosting, cloud hosting, reseller hosting and dedicated servers.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

 

About Us

WindowsHostingBulletin is a professional windows hosting review website to help people find the best windows hosting at the lowest price available. We receive compensation from the web hosting companies whose products we review, though this has no impact on the quality of our reviews.
Copyright © Best ASP.NET Hosting Reviews | Designed by WindowsHostingBulletin.com