Thursday, January 25, 2018

Inserting data in custom list using javascript in SharePoint 2013

1. Create a SharePoint custom list : For an example such as below one

2. Create a javascript file and copy below code into that file.

function SaveVehicle() {

    var listName = "vehicleList";
    var newVINNumber = document.getElementById('txtVINNumber').value;
    var newVehicleYear = document.getElementById('txtVehicleYear').value;
    var newPlateID = document.getElementById('txtPlateID').value;
    var newCurrentMileage = document.getElementById('txtCurrentMileage').value;

    CreateListItemWithDetails(listName, _spPageContextInfo.webAbsoluteUrl, newVINNumber, newVehicleYear,
        newPlateID,newCurrentMileage, function () {
        console.log("New Item has been created successfully.");
    }, function () {
        console.log("Ooops, an error occured. Please try again.");

function CreateListItemWithDetails(listName, webUrl, newVINNumber, newVehicleYear,
        newPlateID,newCurrentMileage, success, failure) {
    var itemType = GetItemTypeForListName(listName);
    var item = {
        "__metadata": { "type": itemType },
        "VINNumber": newVINNumber,
        "VehicleYear": newVehicleYear,
        "PlateID": newPlateID,
        "CurrentMileage" : newCurrentMileage

        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        success: function (data) {
        error: function (data) {

function GetItemTypeForListName(name) {
    return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";

3. Add a "Script Editor" or "Content Editor" Web Part and Add this line of code on clicking of submit button
Include the javascript file which is in step 2 with script tag.

<button onclick="SaveVehicle()">Submit</button>

You can use "Developer Tools" of Browser or "Start Debugging" from Visual Studio to 

Thursday, November 16, 2017

How to get Managed Meta Data Service Information using PowerShell in SharePoint 2013/2016

If you want to get details about the managed meta data service application, there is only onw thing which you must have.

1. Central Adin URL
2. Access to Run "Windows PowerShell ISE"

There are 3 steps.

Step 1:
$site = Get-SPSite ""
Pass Central Admin Application URL as a parameter here to get site object.

Step 2:
$taxSession = new-object Microsoft.SharePoint.Taxonomy.TaxonomySession($site, $true)
To get the taxonomy Session for the Central Admin Site. Pass on Site object here.

Step 3:
This step would give you all the information about "Managed Metadata  Service" Applications which are configured on this farm as of now.

Tuesday, October 3, 2017

Useful Powershell Commands in SharePoint 2013/2016

To Get the default search index location
 $ssi = Get-SPEnterpriseSearchServiceInstance

It would show  the similar output in which the "Index Location" is the location of search indexes.

Id            : b16c2902-7546-4580-aac8-49ddc822eef5
ServerName    :
IndexLocation : C:\Program Files\Microsoft Office Servers\15.0\Data\Office Server\Applications
State         : Ready
DesiredState  : Ready

Clearing all indexes from Search Service Application
 $ssa=Get-SPEnterpriseSearchServiceApplication -Identity "Search Service Application"
Where,$True parameter denotes: Disable Alerts & Ignore Timeout error. 

Setting Global Search Center URL in Search Service Application
$ssa=Get-SPEnterpriseSearchServiceApplication -Identity "Search Service Application"
$ssa.SearchCenterUrl = ""

Changing the master page on SharePoint sites with PowerShell
web = Get-SPWeb http://portal/sites/collaboration
$web.MasterUrl = "/sites/collaboration/_catalogs/masterpage/custom.master"

Start the upgrade process on a site collection
Upgrade-SPSite http://<site name>/sites/testsite -VersionUpgrade

Exports a site, list, or library.
Export-SPWeb http://site -Path "site export.cmp"

Import a site, list, or document library in SharePoint 2013
Import-SPWeb -Identity  <SiteURL>  -Path <ImportFileName>

To Convert the authentication mode of a web application
 Convert-SPWebApplication -Identity "https://<webappurl>" -To Claims -RetainPermissions [-Force]

Upgrades a deployed SharePoint Solution
 Update-SPSolution -Identity contoso_solution.wsp -LiteralPath c:\contoso_solution_v2.wsp -GACDeployment

To Install a SharePoint Hosted App in a site
$spapp=  Import-SPAppPackage -Path Path to app -Site URL -Source Source
Install-SPApp -Web URL -Identity $spapp

To Change the visual Elements of Site collection from SharePoint 2010 to SharePoint 2013
Upgrade-SPSite http://<site name>/sites/testsite

Setting up a new URL for existing site collection in web app
Set-SPSiteURL -Identity $site -Url -Zone Default

To change the ContentType Hub URL in "Managed Metadata Service" Application
Set-SPMetadataServiceApplication -Identity "NYCEDC MMS Application" -HubUri ""

To set the interval for creating ULS Log File
PS C:\Users\contoso> Set-SPDiagnosticConfig -LogCutInterval 60

To set the days interval for keeping the ULS log Files.
PS C:\Users\contoso> Set-SPDiagnosticConfig -DaysToKeepLogs 5

To create  a new Managed path under a web application
New-SPManagedPath "applications" -WebApplication