Saturday, February 6, 2021

Postman : Add item to SharePoint from postman using SharePoint REST api

Postman : Add item to SharePoint from postman using SharePoint REST api (Can be used to add/update items in SharePoint from external application through REST api)

 Problem statement : Leverage Postman desktop or chrome extension to make SharePoint REST api calls to add/update items in SharePoint online site


There are many articles available in internet to make READ type calls from Postman . I am not going to detail out all the basic steps to configure the Postman , rather I will be focusing on the information required to make the ADD/UPDATE type of REST api calls.

Note: I am using Postman desktop application , but you can do the same through Postman Google chrome extension as well . Postman desktop client


Step-1 : Configure app permission in SharePoint Register add-in

Step-2 : Retrieve tenant ID

Step-3 : Retrieve access token 

Step-4 : Connect SharePoint REST api to perform READ operations 

For Step 1 through 4 , I suggest this article which consists of all the details 

Additional reference article 

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/authorization-and-authentication-of-sharepoint-add-ins

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-rest-endpoints


When you are confident that you are able to perform READ operations through Postman per above details , you are good to make next step to make Add/update operations , make below changes to ADD/UPDATE items in SharePoint list/libraries 


App registration 

While you register your app and provide permission level , make sure you are providing Write/Manage/FullControl types of access level , Refer to link App access level .

In my case I was trying to add a new item to SharePoint online list , I opted for below permission level , but you can provide minimum required permission as well 

<AppPermissionRequests AllowAppOnlyPolicy="true">

    <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/" Right="FullControl" />

</AppPermissionRequests>


Follow above process with new client ID and secret to record below items 

  1. Tenant ID (Bearer realm)
  2. ResourceID
  3. Client ID 
  4. Client Secret 
With all this info , as earlier make call to below REST api to retrieve access token

https://accounts.accesscontrol.windows.net/<TenantID>/tokens/OAuth/2

Copy "access_token" from the response


Next step is to try make a Write/Update type REST api call , In my case I wanted to try below REST API call to
add item to SPO list

POST https://{site_url}/_api/web/lists/GetByTitle('Test')/items Authorization: "Bearer " + accessToken Accept: "application/json;odata=verbose" Content-Type: "application/json;odata=verbose" Content-Length: {length of request body as integer} X-RequestDigest: "{form_digest_value}" { "__metadata": { "type": "SP.Data.TestListItem" }, "Title": "Test" }


As you can see we need 2 items highlighted in yellow to make this call
  1. Form digest value
  2. ListItemEntityTypeFullName - This is different for each list/Library
Retrieve "Form digest value"

We can use Postman to retrieve form digest value through below REST api call - Reference Link

https://SiteCollection/_api/contextinfo

In the header for this call you need to include

  • Accept - application/json;odata=verbose
  • Authorization - Bearer "Access token value"
Save the form digest value you receive in property " "FormDigestValue"

Retrieve "ListItemEntityTypeFullName "

Make another call as below to retrieve ListItemEntityTypeFullName 

https://SitecollectionURL/_api/web/lists/GetByTitle('ThiloshList')?$select=ListItemEntityTypeFullName

You should see a response as below , copy the value 

{
    "ListItemEntityTypeFullName""SP.Data.ThiloshListListItem"
}


Make SharePoint REST api call to add item to SharePoint Online list 


Make REST api  POST call to 

https://SiteCollectionURL/_api/web/lists/GetByTitle('ThiloshList')/items

With below parameter in header

  1. Accept - application/json;odata=nometadata
  2. Authorization - Berer [access token]
  3. X-RequestDigest - [Form digest value previously copied]
  4. Content-Type - application/json;odata=verbose

In the Body , copy below JSON 

{
  "__metadata": {
    "type""SP.Data.ThiloshListListItem"
  },
  "Title""Test"
}

This will
  1. Authenticate the application
  2. Add the "test" item into "ThiloshList" SharePoint Online list


You can use same process to make any other ADD/Update SharePoint REST api calls.






Thursday, January 16, 2020

Issue in installing "yo" (yeoman" module/package globally through npm - nodeJs


I was trying to update/reinstall "yo" module through npm commands and it was throwing below error message

Error: Cannot find module 'request'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\THINAG\yo\node_modules\duplexer2\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\THINAG\yo\node_modules\har-validator\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\THINAG\yo\node_modules\request\package.json'

npm ERR! Failed at the yo@0.0.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
verbose enoent This is related to npm not being able to find a file.





I was not able to find any solution in internet , after a bit a struggle , trial and error I was able to find a solution .

Issue was that , I had a previous version of yo installed in the same machine some time last week , even though you use below command to uninstall the yo module from npm , it was not cleaning up all the directory from the machine .

npm uninstall -g yo

Below steps fixed the issue

1)Uninstall the existing yo module

          npm uninstall -g yo

2)Make sure it is cleaned up by running 
     npm list -g --depth=0
3) Clean the folder with name "yo" or any file which belong to yomen
at  C:\Users\THINAG(This is my directory , you can change accordingly"
at C:\Users\THINAG\AppData\Roaming\npm\node_modules
4)Run below command in npm
    npm cache clean -f 
5)Try installing the module again
    npm install -g yo

while you run npm list -g --depth=0  it should not return any error .
















Tuesday, December 18, 2018

SharePoint upgrade missing feature reference issue

While I tried to migrated the SharePoint 2010 Data base to SharePoint 2016 through the database upgrade approach , I received the below missing feature error

Database [database] has reference(s) to a missing feature: Name = [PowerPivot Feature 
                  Integration for Site Collections], Id = [1a33a234-b4a4-4fc6-96c2-8bdb56388bd5

usually if you follow this blog Link, you should be able to clean up the missing feature , if not by using the feature admin tool you should be able to clean up the faulty feature at the source . But in this case neither worked . SharePoint 2010 was not showing that this feature was activated , but the upgrade was failing in SharePoint 2013/2016 .

Hence i decide to do some digging myself  in SQL and try to resolve the issue , below are the steps followed to resolve the issue




1.      Open SSMS in source (SharePoint 2010 /2013), run the below script to find the tables in DB where the missing feature is referenced

USE [Name of the DB]
GO
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%FeatureId%'
ORDER BY schema_name, table_name;

2.      Query result would provide the list of tables in SQL

table_name        schema_name   column_name
AllLists                  dbo                       tp_FeatureId
CustomActions   dbo                       FeatureId
Features              dbo                       FeatureId
FeatureTracking dbo                      FeatureId

3.      Open up each table in SQL and identify the row as per sample query

Select * from [data base name].[dbo].[tablename] where tp_featureID = ‘guid of missing feature’

Results would provide the webID of the website

4.      Open up any of the SharePoint server in the farm and execute the below query , this would list all the site and webs with the ID
5       
Get-SPWebApplication http://sharepoint.dev.symetra.com/ | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, URL, ID, ParentWebID | Export-CSV C:\InfoArch.csv –NoTypeInformation

6.      Navigate to the website and clean up the component which is referred by the feature .

I In my case there was a faulty power pivot library at SharePoint 2010 , I went ahead and cleaned up the library at 2010

Thursday, December 13, 2018

Sharepoint 2016 User profile sync unable to update manager field



I was migrating a User profile from SharePoint 2010 to SharePoint 2013 and then to SharePoint 2016 . During the process of migration I did decide to leave out the sync and social DB , as we wanted the   new social features available in SharePoint 2016 and we decided not having to migrate the social and sync DB from SharePoint 2010 would be a cleaner approach .

As per the Microsoft article I did migrate the User profile DB and the MySite DB through Data base upgrade process. Everything did migrate all fine and I did opt for "Active Directory Import" to configure the new Sync in SharePoint 2016 . I was able to create a custom property to import the "Employee ID " from AD and post completion of Full sync ,I was able to see the Employee ID property in user's profile .

Strangely I noticed that the manager field was not being updated , yes it did have the old values carried over from SharePoint 2010 , but if the manager field was updated in AD , it was not being synced to SharePoint . Did restart the service and triggered full sync of user profile on few occasion , but this did not resolve the issue .

But below steps finally synced the manager field from AD to SharePoint 2016 .


  1. Clicked "Configure Synchronization Settings" in central admin of SharePoint 2016
  2. Since I had configured the "  Active Directory Import " to sync the data from AD , this option was selected .
  3. Select the "Enable External Identity Manager" 
  4. click OK
  5. Now get back to the same screen ""Configure Synchronization Settings"
  6. But this time select the right setting "Use SharePoint Active Directory Import"
  7. Click OK
  8. Trigger the "Full Sync"

This resolved the issue and manager field for all the users were updated .

Note : Manager property should not be configured with any import filed in "Manage User Property" this field has to be kept blank , only then the SharePoint 2016 would sync  the data from AD .

Previously in SharePoint 2010 , you had to map the SharePoint "manager" user property with "manager" field in "Property mapping for synchronization"

Friday, September 21, 2018

SharePoint 2010 to SharePoint 2016 MySite blog migration issue



While we were trying to migrate the User profile DB along with the Mysite from SharePoint 2010 to SharePoint 2016 by having a hop at SharePoint 2013 , we faced the below issue

It worked all fine in SharePoint 2013 , but had some issue in SharePoint 2016

Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe

On closer look at the web.config and logs , I found that the entries were missing for 14.0.0.0 version in Sharepoint 2016 , fix was to add below entries in web.config file which was hosting the Mysite webapplication

<SafeControl Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebPartPages" TypeName="BlogAdminWebPart" Safe="True" SafeAgainstScript="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebPartPages" TypeName="BlogLinksWebPart" Safe="True" SafeAgainstScript="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebPartPages" TypeName="BlogMonthQuickLaunch" Safe="True" SafeAgainstScript="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebPartPages" TypeName="BlogYearArchive" Safe="True" SafeAgainstScript="True" />

Issue seems to be either the upgrade had failed in SharePoint 2013 or SharePoint 2016 , hence failed to upgrade the default webpart for blogs , or MS forgot to update their webconfig file 




Thursday, June 21, 2018

SharePoint 2016 search crawl issue

I had the below issue in our SharePoint 2016 farm , for some reason it was working fine until a patch was applied and the server was rebooted . The patch had nothing to do with it though

Issue 

1)Access is denied. Verify that either the Default Content Access Account has access to this repository, or add a crawl rule to crawl this repository. If the repository being crawled is a SharePoint repository, verify that the account you are using has "Full Read" permissions on the SharePoint Web Application being crawled.

2)Crawling of this item failed, HTTP 504: Gateway Timeout. Try accessing the item using a browser on the crawl machine. If URL is accessible through the browser, it is possible that the crawl targets for that host are not configured correctly. Please contact the Host Administrator for assistance
Error refers to disabling the loop back but this has already been done , but we can remove the registry entry and try again though , also we could try applying the latest patch . But all this would require change in registry and reboot of server .

First error message was seen for the HTTP site and the second error message was seen for the HTTPS site

1)We did try to add the crawl rule and assign certificates to crawl the HTTPS URL , but nothing resolved the issue
2)But as a standard procedure , you will need to follow the steps in below link to make sure you have the right configuration for search

https://social.technet.microsoft.com/wiki/contents/articles/25863.access-is-denied-verify-that-either-the-default-content-access-account-has-access-to-this-repository-or-add-a-crawl-rule-to-crawl-this-repository.aspx

3)I had all the configuration set correctly , but it still would not work
Finally by clearing the proxy did the magic

below  are the script to be run as admin on the SharePoint server which is defined as crawler

netsh winhttp show proxy
netsh winhttp reset proxy
Net stop Osearch16
Net start Osearch16

Saturday, December 23, 2017

Sharepoint framework(SpFx) gulp error -gulp serve cannot find module semver

If you get an error while trying to kick start your first SharePoint Framework solution


"gulp serve cannot find module semver"


Go to terminal and type in the below command


"npm install gulp-cli -g"


This should probably solve your issue

Tuesday, December 5, 2017

SQL data connection issue on SharePoint 2016 hosted on SQL 2016 and Windows 2016

We were trying few test migration and built our SharePoint server 2016 on top of SQL 2016 and windows 2016 . We did want to try SSRS connection after the test migration from SharePoint 2010 to SharePoint 2016 .

We were having issue with the data connection , even if we created new .rsds file and tried to connect to a DB which was hosted on SQL 2008 R2 we were receiving the error as below

"A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - An existing connection was forcibly closed by the remote host.)"

 I spent long hours trying to figure out if it was SharePoint issue or SSRS configuration issue even I did double check if Office online server was causing the issue , finally was able to back track the issue was with the SQL component on Windows 2016 OS . As per the new standard the SQl client hosted on Windows 2016 would not allow TLS1.0 communication and the minimum it supports in TLS1.2 .

Found a article which was put accross by Microsoft regarding the same and by installing a patch on SQL 2008 R2 and adding the necessary registry key , SQL as well as Sharepoint was able to communicate to legacy version of SQL instance .

Link --> https://blogs.msdn.microsoft.com/sqlreleaseservices/tls-1-2-support-for-sql-server-2008-2008-r2-2012-and-2014/


Thursday, October 12, 2017

Getting started with NodeJs,NPM,VsCode,Typescript and webpack

It is a quite reading if you are coming from a .net development experience to work on client side programming , below are few steps which can be used to get started with the modern web development stack .

Basically you would need a Laptop or desktop as usual :) windows or IOS license is all you need 
and then 

1)Code editor : you can use notepad++ , atom , sublime , I personally use VSCode editor (https://code.visualstudio.com/) Its completely freeeeeeeee !!
2)Git : If you need to have a repository and manage versions , you can use VSTS too . (https://git-scm.com/)
3)NodeJs :Platform used to build and test application 
4)NPM : .net developers can compare this to NugetPackage manager .this helps us to download and install the required package which will be used in the web development 
5)Typescript : You can refer this for installation , I would prefer global installation  (https://www.npmjs.com/package/typescript)
6)Task runners: Which will help to automate the development life cycle , there are many Gulp,Grunt,Webpack etc , I have used Webpack in the below sample . The help to automate compilation , bundling of the files even magnification of JS files .

Getting started : 

1)Open VS code
2)cmd (can be any terminal) -- > npm init (Package.json will be created)
3)cmd -->  npm install --save-dev typescript (Creates the local typescript files and a compile component tsc)
4)Create folder to add a  .ts file (custom coding files)
5)Create tsconfig.json and provide entries (Files to be included for transpiling)

for Webpack
1)cmd -- >npm install --save-dev ts-loader (Installs ts loader locally -this helps webpack to compile ts files)
2)cmd --> npm install --save-dev webpack (Installs webpack loacally)
3)Add "webpack.config.js" (This will be used for compiling and build )
4)run "node_modules\.bin\webpack" (provides the output of the build which is a js file which can be directly used in HTML)


Debugging
1)Add line "debugger" in any ts file
2)Open up the html in debug mode , this enters the debug mode but the code is in transpiled state , to get the code in typescript format , perform below steps
3)Open "tsConfig.json" --> add property "ComplierOptions" -->"sourceMap" :true
4)Open "Webpack.config.js --> inside exports add -->devtool: 'source-map',
5)This would load the ts file in the browser


Http-server
1)Cmd -- > Install --save-dev http-server (to install the http server locally)
Auto build through webapcak
2)webpack.config.js --> add property --> watch:true ;
3)To test or run an application in local server use cmd --> node_modules\.bin\http-server

Jquery
1)cmd --> npm install --save jquery (This will install the Jquery package globally- as this package has to be released to browser)
2)run as admin Cmd -- >npm install --save-dev @types/jquery (This will install the Jquery declaration file , this is one of the way to work with Jquery)
3)May get a error on Jquery , if so add the property "lib": ["dom","es5","es2015.iterable"]

4)cmd -- >node_modules\.bin\webpack should give you the bundled file including the Jquery library .

Get started with the project from repository
1) cmd -- > npm install  (This would install all the required package into node modules by referring the package.json)


-------------------------------------------------------------------------------------------------------------------------
tsconfig.json

{
"files": [
"./ts-src/alert.ts"
],
"compilerOptions": {
"lib": [
"dom",
"es5",
"es2015.iterable"
],
"sourceMap": true,
"outDir": "./dist1/",
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"allowJs": true
}

}

package.json


{
"name": "typescriptwithjquery",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/jquery": "^3.2.12",
"http-server": "^0.10.0",
"ts-loader": "^2.3.7",
"typescript": "^2.5.2",
"webpack": "^3.5.6"
},
"dependencies": {
"jquery": "^3.2.1"
}
}

webpack.config.js


const path = require('path');

module.exports = {
devtool: 'source-map',//only to debug
entry: './ts-src/alert.ts',
module: {
rules: [{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}]
},
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
//watch:true,
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
};

alert.ts

import news from './sample'
import * as $ from 'jquery'
/*
window.onload = function(){
var a1 = new news();
a1.msg();
}
*/

$(function(){
$('#btn1').on("click",function(){
var a = new news();
a.msg();
});

});

sample.ts
import * as $ from 'jquery'

export default class message{
msg(){
$("#btn1").html('Thilosh');
alert('hi');
}
}

index.html


<html>
<head>
<script src="dist/bundle.js" ></script>
</head>
<body>
<button id="btn1" >click here</button>

</body>
</html>


Note:

--save-dev  will install the packages locally in the loacl project 
-g  will install the package global 

Tuesday, August 22, 2017

SSRS issue in SharePoint 2013 integrated mode .

I did recently come across an issue with SSRS in SharePoint 2013 integrated mode , the error was while opening up a SSRS report . Error stated as below


·        An error occurred during client rendering.
o   The requested service, 'http://serverName:32843/39c0f43bbd794f929239eb6ede09edb6/ReportStreaming.svc' could not be activated. See the server's diagnostic trace logs for more information.

The requested service, 'http://serverName:32843/39c0f43bbd794f929239eb6ede09edb6/ReportStreaming.svc' could not be activated. See the server's diagnostic trace logs for more information.


There was no much information on the above issue , only way to figured out the issue was by testing the SSRS webservice URL


open the management studio and enter below command
Get-SPRSServiceApplication

You will get the result with Name,ID and UEAccountName

You can frame the report service webapplication ID with this GUID as below

1)    http://serverName:32843/39c0f43bbd794f929239eb6ede09edb6/ReportingWebService.svc --> this URL is working fine 
12)http://serverName:32843/39c0f43bbd794f929239eb6ede09edb6/ReportStreaming. à this one throws a error as below 


Memory gates checking failed because the free memory (208904192 bytes) is less than 5% of total memory.  As a result, the service will not be available for incoming requests.  To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.



Increasing the RAM of the server resolved the issue

Thursday, August 10, 2017

Secure store service issue in SharePoint 2013

Recently were trying some tests on migration of SharePoint 2010 contents to SharePoint 2016 , having SharePoint 2013 as intermediary server without which the migration will not be successful .

Had this weird issue of Secure store service application not being created in SharePoint 2013, the farm was built by someone a yr ago , so did not have the full data on the issue , but below were the errors in ULS

Microsoft.SharePoint.SPException: Your session has expired. Restart this wizard to continue.  
 at Microsoft.SharePoint.Administration.SPScenarioContext.GetContext(Page page, CultureInfo culture)   
 at Microsoft.Office.SharePoint.ClientExtensions.SecureStoreAdministration.CreateSSSApplicationStateInfo.OnLoad(EventArgs e) 

Application error when access /_admin/sssvc/createsssvcapplicationstateinfo.aspx, Error=Your session has expired. Restart this wizard to continue. 


The current state '_admin/sssvc/createsssvcapplication.aspx' doesn't match the Page '_admin/sssvc/createsssvcapplicationstateinfo.aspx'


I was unable to fix this issue not the root cause of it yet , but figured it out that this was an issue only through the UI , so I could still go ahead the create a new Secure store service application through power shell 

New-SPSecureStoreServiceApplication -ApplicationPool "app pool name which already exists" -AuditingEnabled:$false -DatabaseServer "devomasp02" -DatabaseName "Secure store SANew"-Name "Secure store SANew"

$secureStoreApplicationName  ="Secure Store Service Application"
Get-SPServiceApplication | ? {$_.GetType().Equals([Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplication])} | New-SPSecureStoreServiceApplicationProxy -Name $secureStoreApplicationProxyName -DefaultProxyGroup | Out-Null

I shall look into issue and keep posted if I fix it 

Friday, September 16, 2016

Using Custom fonts in SharePoint

You can use the custom fonts in SharePoint applications ,below are the few things you may have to perform in order to get the new stylish fonts which you want to display to your users in your application .

My experience was to try use the "Avenier" fonts ,this is a paid font and it is been widely used these days .

1)I received the few packages like "Avenir Next Condensed.ttc" "Avenir Next.ttc" "Avenir.ttc"
2) If you try to use these package directly on to your site it will not work ,as the the extension of the file says it is a collection  "TrueType collection font file" .
3)Hence use some tools (many tools are readily available online)  to convert the truetype collection font file to "TrueType font file.
4)What it basically does it breaks the collection of files into individual files (ttf from ttc)
5)Now there are many different formats of font file you can use in your application
6)I have again used the online converter and converted my ttf  files to ".woff"  format
7)Upload these files in any of the document library (eg: site assets"
8)Now you are ready to use your new font in your css file as below

@font-face {
      font-family: "ThiloshNewFont";
      src: url("http://SiteCollection/SiteAssets/HLS-LEAD-FontFamily/AvenirNext-DemiBold.woff");


using in the custom class as below 


.testNewclass
{

     font-family: "ThiloshNewFont";

}


So now in which ever HTML element you use this ".testNewClass" the font style applied will be  "AvenirNextDemiBold"


Thursday, May 19, 2016

Add items to Sharepoint having multiselect Lookup through SharePoint REST


If you are trying to add the list items in the normal way using the REST you would probably get this error

"an unexpected 'primitivevalue' node was found when reading from the json reader"

This is because you would have used the wrong format of people picker or lookup field to update or add item .Below eg "spLookup" is my lookup field and is multiselect .Sharepoint creates the field named spLookupId .


function CreateListItems(){
var data = {
    __metadata: { 'type': 'SP.Data.ThiloshListItem' },
    Title: 'Create from the REST code',  
    spLookupId : { 'results': [1,2] }
};

var url = "/_api/web/lists/getbytitle('thilosh')/items";
var siteurl = "https://thilosh1224456.sharepoint.com/sites/TeamSite"
//var test = __spPageContextInfo.webAbsoluteUrl;
$.ajax({
       // url: __spPageContextInfo.webAbsoluteUrl + url,
   url : siteurl + url,
        type: "POST",
        headers: {
            "accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "content-Type": "application/json;odata=verbose"
        },
        data: JSON.stringify(data),
        success: function (data) {
            $("#resultArea").append("Item added from REST code");
        },
        error: function (error) {
            alert(JSON.stringify(error));
        }
    });
}

Wednesday, May 11, 2016

SharePoint 2016 Installation and Configuration + Workflow Manager



As you would know the SharePoint 2016 was made available for general public a few days ago .I am lucky enough to get my hands on it .Below is my experience and troubleshooting with installation of SharePoint 2016 and configuring it .
       I tried the single server installation here ,as it was my Development server ,so i created a LocalUser account .For production environment it is always recommend you use the Service account which is a Active Directory account.

1)Download the SQL server 2014  standard/Enterprise .
2)Download the SharePoint server 2016
3)Download the Visual Studio 2015 enterprise.

4)I started with SQL server installation and added all the features except the native reporting service which i am pretty sure I was not going to use ,if required I would use SharePoint integrated mode for Reporting . There are number of materials available on internet if you are doing the installation and configuration of SQL for first time ,I aint going to explain the same here .It is pretty simple if you follow the steps .I would recommend you to configure SQL in Mixed mode ,add a SQL account too .I gave the Admin right to the LocalUser for the SQL services.

5)Luckily all is well SQL got configured succesfully !!

6) Next up SharePoint 2016 , before touching this ,I would recommend you check the internet connection ,make sure its accessible as the pre-installer would need the internet to download the required SW .
7)Click on the prerequisite.exe , it would run and download and configure all the required SW for sharepoint installation .
8)Once done it would restart the machine .
9)Next up the big man SharePoint 2016 !!
10) Click on Setup.exe and run the installation 
11)It would ask for product key provide one
12)You would end up in a window which ask for farm id to configure and database server 
13) You provide the LocalUser  as configuration account you would end up in a error as below

Local User cannot be used to configure Sharepoint ,use domain user  !!

If you had the experience with installation of older SharePoint versions you would know that ,Since it is a Standlone config you dont require domain account to configure .Because all my SQL ,sharepoint etc are in same machine . Also you have a work around to overcome the issue .You would create Config DB through powershell and later run the configuration again 

14)So I did the same  opened Powershell and typed 

New-SpconfigurationDatabase

Unfortunately this wasnot working out !!

Reason one or more parameter is missing 

15) Oh I realised now !! New feature in SharePoint 2016 ,you could assign the role to the server during the installation itself ,you can install as AppServer ,webFront end ,Distributed cache server etc etc .lot more info available on internet :)

So I tried the below commands


New-SPConfigurationDatabase -LocalServerRole SingleServerFarm

Since I was running everything in same machine I gave server role as SingleServerFarm

It would ask for few input provide the same and 

Your Config DB is created just with the local account now  :)

Run the SharePoint Configuration Wizard ,It ask you to disconnect or remain in same farm .
Choose option to Remain  and proceed with the configuration  .

My SharePoint 2016 Site was up and running  :)

So now the SharePoint 2016 config was done ,I was in search on supporting tools

16)There is no SharePointPoint available and SharePoint 2013 to be installed to do the job.

17)For the Workflow configuration you still have the framework which is being used in the Sharepoint 2013 

Install Webplatform installer  .

18) Search for Workflow Manager 1.0 Refresh   and install ,
19)This would also install the ServiceBus ,Workflow client and Appfabric .
20)After the installation a Configuration wizard is run to configure the Service bus and WF .Number of materials are available to assist on this as it is a old process .

21) Error in WF configuration  the api-version in the query string is not supported

Found out that this issue is due to the Service bus 

Installion Service bus cummulative update fixed the issue !!

22) Next step as usual as in SharePoint 2013 once the WF configuration Wizard is completed ,Run the Powershell command to create service application in sharepoint .So I opened Sharepoint Management Studio and typed in the below commands 

Register-SPWorkflowService -SPSite "http://sharepointst/sitecollection" -WorkflowHostUri "http://sharepointst:12991"

Since I was using http for WF i used the 12991 port ,you can config for https too ,again internet has the info to help you out on this .

23)Found the below error 

Forbidden erorr 503

24)Luckily this error is familar to me ,I had worked on this 2 yrs ago while working on sharepoint 2013 RTM version and the resolution is here in my other blog

http://sharepointerthilosh.blogspot.in/search/label/workflow/

25)Now All is well Start working on SharePoint 2016 


Planning to integrate SharePoint 2016 with SSRS in integrate mode ,hoping to update the post on the same ASAP :)

Happy coding !! :) :) 

(Updated  the Post with below details)

After all this successful messages I thought it would be a cake walk using Visual studio 2015 with Sharepoint ,to my surprise I did not find the Sharepoint 2016 templates  in VS2015 ,as usual i installed the Office developer tools for Visual Studio 2015 ,was able to find the templates for 2010 and 2013 development was sharepoint but no signs of 2016 templates . Finally after lot of goooooling found that there are two versions of Visual Studio 
Visual Studio 2015 and Visual Studio 15 .So I ended up do trail and error with all the combinations of VS and developer tools and finally found the below two are the ones which provided me with Sharepoint 2016 templates .

Visual Studio 15 preview  -->link
Microsoft Office developer Tools Preview -- >Link

Looks like these two packages are still not released as final versions  !! Comment below if I am wrong  :) :) 







Friday, November 27, 2015

SharePoint Migration Lookup error

There was site in SharePoint 2010 and I was planning to move it to SharePoint 2013 version by performing a Content db migration .

The site had a list which consists of lookup columns ,these were lookup to other list.But the point here was that these columns were hidden while it was created through element.xml in the solution .The list was working fine in SharePoint 2010 ,But when I migrated the 2010 site to SharePoint 2013 the link of the lookup is lost and the data is been displayed as a text field Eg: "#2;lookupValue" etc .
This was creating few problems in my solution due to mismatch in the values of the list itms .I had to fix the lookup column .Below is the resolution to this migration error



I placed the below code in Content Editor WebPart and made the field readable,This changed the column back as lookup .Later you can change the column to readonly =true


<content id="Main" contentplaceholderid="PlaceHolderMain" runat="server"></content><script language="ecmascript" type="text/ecmascript">
        var fieldCollection;
        var field;
        var list;
        function UpdateField() {
            var clientContext = SP.ClientContext.get_current();
            if (clientContext != undefined && clientContext != null) {
                var webSite = clientContext.get_web();
                this.list = webSite.get_lists().getByTitle("ListA");
                this.fieldCollection = list.get_fields();
                this.field = fieldCollection.getByTitle("Column1");
                this.field.set_readOnlyField(false);
                this.field.update();

            clientContext.load(this.fieldCollection);
            clientContext.load(this.field);
                clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
            }
        }
        function OnLoadSuccess(sender, args) {
            alert("Field deleted successfully.");
        }
        function OnLoadFailed(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        }
</script><input type="button" id="btnUpdateField" onclick="UpdateField()" value="Change ReadOnly"/> 

Jquery function after delay


Some times functions under the method " $(document).ready(function()" doesnot get called .You can use the delay as below and call the events.

setTimeout(function()
{
$(document).ready(function(){
$("#downloads").click(function (e) {

                alert('test');

            });
});},1000);

Tuesday, September 8, 2015

Move Sharepoint folders and files in list/Libraries through powershell



I had this folder movement structure of
1)Adjacency
    2)Group
          3)Subgroup

Below is the Powershell code through which I achieved it.It can be used to move files and folders in the same library or to different library.You could also pick only the subfolders to be moved or the whole main folder to be moved



$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}


$logFile = "LogFile_MoveFiles.txt"

function create-fileitems()
    {
     [CmdletBinding()]
     param(
[Parameter(position=1, mandatory=$true, parametersetname="Default")] [Microsoft.SharePoint.SPDocumentLibrary]$SourceList,
[Parameter(position=2, mandatory=$true, parametersetname="Default")] [Microsoft.SharePoint.SPDocumentLibrary]$DestinationList,
     [Parameter(position=3, mandatory=$true, parametersetname="Default")] [string] $SourceAdjacencyToMove,
     [Parameter(position=4, mandatory=$true, parametersetname="Default")] [string] $ConfirmAdjToMove,
     [Parameter(position=5, mandatory=$true, parametersetname="Default")] [string] $SourceGroupToMove,
     [Parameter(position=6, mandatory=$true, parametersetname="Default")] [string] $DestinationAdjToMove,
     [Parameter(position=7, mandatory=$true, parametersetname="Default")] [Microsoft.SharePoint.SPWeb]$sourceweb
     )
        $src = $SourceList
        $tgt = $DestinationList
        $SourceAdjacency = $SourceAdjacency
        $AllFolders = $src.Folders
        $srcRootFolder = $src.RootFolder
        $allfiles = $src.items
        $RootItems = $srcRootFolder.files
        $destRootFolder = $tgt.RootFolder
        $arrListFolderURLToDelete = New-Object System.Collections.ArrayList
        Try
         {
          foreach($Folder in $src.RootFolder.SubFolders)
           {
         if($Folder.Name -eq $SourceAdjacencyToMove)
           {
            $srcFolderURL = $folder.url
            $destFolderURL = $srcFolderURL          
            $destFolderURL = $destFolderURL -replace $SourceAdjacencyToMove, $DestinationAdjToMove
            $srcItems = $Folder.folder.files
            if(!($tgt.Folders | ? {$_.URL -eq $destFolderURL}))
            {
             
                $parentFolderURL = $Folder.ParentFolder.ServerRelativeUrl
                $newFolder = $src.Additem($parentFolderURL,[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$DestinationAdjToMove)
                $newFolder.Update()
                write-host -ForegroundColor Green "Folder Creation:"$destFolderURL" - Complete"
                Add-Content $logFile "Folder Creation: $destFolderURL - Complete"
            }          
               foreach($subFolder in $Folder.SubFolders)
               {
                   if($ConfirmAdjToMove -eq "N" -or $ConfirmAdjToMove -eq "n")
                     {
                        if($subFolder.Name -eq $SourceGroupToMove)
                        {
                            MoveGroup $Folder $subFolder $srcRootFolder $destRootFolder $tgt $AllFiles
                            $arrListFolderURLToDelete.Add($subFolder.URL) | Out-Null
                        }
                     }
                   else
                     {
                       MoveGroup $Folder $subFolder $srcRootFolder $destRootFolder $tgt $AllFiles
                       $arrListFolderURLToDelete.Add($subFolder.URL) | Out-Null
                     }
                   
               }
             if($ConfirmAdjToMove -eq "Y" -or $ConfirmAdjToMove -eq "y")
               {
                 $arrListFolderURLToDelete.Add($Folder.URL) | Out-Null
               }  
                     
           }

        }
          Foreach($folderURLToDelete in $arrListFolderURLToDelete)
           {

                $folderToDelete = $sourceweb.GetFolder($folderURLToDelete)
                $folderToDelete.Delete()

             }
         }
        catch
         {
            Write-Host  $_.Exception.Message
            Add-Content $logFile    "***Error description Starts****`n"
            Add-Content $logFile    $_.Exception.Message      
            Add-Content $logFile    "***Error description ends****`n"
         }

      }

 function MoveGroup($Folder,$subFolder , $srcRootFolder ,$destRootFolder,$tgt,$AllFiles)
    {
        $srcSubFolderURL = $subFolder.url
        $destSubFolderURL = $srcSubFolderURL                  
        $destSubFolderURL = $destSubFolderURL -replace $SourceAdjacencyToMove, $DestinationAdjToMove
        $srcSubItems = $subFolder.folder.files
          if(!($tgt.Folders | ? {$_.URL -eq $destSubFolderURL}))
              {
                        $parentFolderURL = $Folder.serverrelativeurl
                        $parentFolderURL = $parentFolderURL -replace $SourceAdjacencyToMove, $DestinationAdjToMove                                              
                        $newFolder = $src.Additem($parentFolderURL,[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$subFolder.name)
                        $newFolder.Update()
                        write-host -ForegroundColor Green "Folder Creation:"$destSubFolderURL" - Complete"
                        Add-Content $logFile "Folder Creation: $destSubFolderURL - Complete"
                      }
                   
                foreach($sub2Folder in $subFolder.SubFolders)
                      {
                            $srcSub2FolderURL = $sub2Folder.url
                            $destSub2FolderURL = $srcSub2FolderURL                          
                            $destSub2FolderURL = $destSub2FolderURL -replace $SourceAdjacencyToMove, $DestinationAdjToMove
                            $srcSub2Items = $sub2Folder.folder.files
                            if(!($tgt.Folders | ? {$_.URL -eq $destSub2FolderURL}))
                              {
                                $parentFolderURL = $subFolder.serverrelativeurl              
                                $parentFolderDestination = $destRootFolder                              
                                $parentFolderURL = $parentFolderURL -replace $SourceAdjacencyToMove, $DestinationAdjToMove                                                      
                                $newFolder = $src.Additem($parentFolderURL,[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$sub2Folder.name)
                                $newFolder.Update()
                                write-host -ForegroundColor Green "Folder Creation:"$destSub2FolderURL" - Complete"
                                Add-Content $logFile "Folder Creation: $destSub2FolderURL - Complete"
                              }
                     
                       $destFolder = $src.Folders | ? {$_.url -eq $destSub2FolderURL}
                             if($sub2Folder.Files.count -gt 0)
                              {
                                $srcItems = $sub2Folder.Files
                                    foreach ($item in $srcItems)
                                    {
                                        $sourceListItem = $item.Item
                                        [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::UndeclareItemAsRecord($sourceListItem)
                                        $Relative = $Item.URL
                                        $TargetItem = $AllFiles | ? {$_.URL -eq $Relative}
                                        $sBytes = $TargetItem.File.OpenBinary()
                                        $dFile = $destFolder.Folder.Files.Add($TargetItem.Name, $sBytes, $true)
                                        $ditem = $dfile.Item
                                        $ditem["Modified"] = $Item.TimeLastModified.ToLocalTime()
                                        $ditem["Created"] = $Item.TimeCreated.ToLocalTime()
                                        $ditem["Author"] = $Item.Author
                                        $ditem["Editor"] = $Item.ModifiedBy                                                                              
                                        $ditem.SystemUpdate($true)
                                        $dFile.CheckIn("Check in by Administrator")
                                        $dFile.Update()
                                        write-host -ForegroundColor Green "File Creation:" $dfile.name" - Complete"
                                        Add-Content $logFile "File Creation: $dfile.name - Complete"
                                    }
                               }
                       }
   }
 


$siteURL = Read-Host "Enter the Site collection URL - Eg:http://Yourwebapplication:1234/ "
$site = Get-SPSite -Identity  $siteURL
$sourceweb = $site.Openweb()
$sourcelist = $sourceweb.lists["LibraryA"]
$destinationlist = $sourceweb.lists["LibraryB"]

$SourceAdjacencyToMove = Read-Host "Enter the name of source Adjacency to be moved"
$DestinationAdjToMove = Read-Host "Enter the name of Destination Adjacency where the files has to be moved to :"
$ConfirmAdjToMove = Read-Host "Press (Y) to move all files ,Press (N) to select Group"


if($ConfirmAdjToMove -eq "N" -or $ConfirmAdjToMove -eq "n")
    {
        $SourceGroupToMove =Read-Host "Enter the Name of Group to be moved"
        create-fileitems -sourcelist $sourcelist -destinationlist $destinationlist -SourceAdjacencyToMove $SourceAdjacencyToMove  -ConfirmAdjToMove  $ConfirmAdjToMove -SourceGroupToMove $SourceGroupToMove -DestinationAdjToMove $DestinationAdjToMove -sourceweb $sourceweb
    }
elseif($ConfirmAdjToMove -eq "Y" -or $ConfirmAdjToMove -eq "y")
    {
        $SourceGroupToMove = " "
        create-fileitems -sourcelist $sourcelist -destinationlist $destinationlist -SourceAdjacencyToMove $SourceAdjacencyToMove  -ConfirmAdjToMove  $ConfirmAdjToMove -SourceGroupToMove $SourceGroupToMove -DestinationAdjToMove $DestinationAdjToMove  -sourceweb $sourceweb
    }




Note: I am using the "[Microsoft.Office.RecordsManagement.RecordsRepository.Records]" because I am working on the Record center and my files are marked as records .Without un-declaring as record ,you cannot perform any action on the document even through powershell or through C# codes.