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
    };

    $.ajax({
        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) {
            success(data);
        },
        error: function (data) {
            failure(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 "http://tailspin.com:21332/"
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:
$taxSession.TermStores
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
 $ssi.Components

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

Id            : b16c2902-7546-4580-aac8-49ddc822eef5
ServerName    : contoso.com
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"
$ssa.reset($true,$true)
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 = "
http://contoso.com:44494"
$ssa.update()

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


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 http://contoso.sharepoint.com -Zone Default


To change the ContentType Hub URL in "Managed Metadata Service" Application
Set-SPMetadataServiceApplication -Identity "NYCEDC MMS Application" -HubUri "http://contoso.com:45518/sites/ContentTypeHub/"


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 http://contoso.com:44495