Friday, August 7, 2015

Auto-numbering InfoPath forms for large SharePoint form library

Recently i observed one issue- users were not able to create tickets on form libraries which having many items or say libraries crossed threshold limit.

Some form libraries used max(@ID) + 1  logic to get last item ID for ticket creation and some used XML Connection using SharePoint View. Both the options doesn't work for form libraries which having many items.

Best solution to overcome this issue is, use REST connection to get last item ID. Use below REST URL format

http://sitecollection/site/_vti_bin/ListData.svc/LibraryName()?$top=1&$orderby=Id%20desc&$select=Id

Ex.

http://contoso/sites/Systems/_vti_bin/ListData.svc/Tickets()?$top=1&$orderby=Id%20desc&$select=Id


Tuesday, June 2, 2015

Get all sites in a SharePoint Site Collection using the PowerShell and CSOM


$host.Runspace.ThreadOptions = "ReuseThread"

#Function definition
function Get-AllSites($siteUrl, $userName, $password, $domain)
{
    try
    {  
        #Save result in temp variable
        $results = @()

        #Create client context
        $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) 
        $credentials = New-Object System.Net.NetworkCredential($userName,$password,$domain)  
        $ctx.Credentials = $credentials 

        #Get site
        $rootSite = $ctx.Web
        
        #Loading root site     
        $ctx.Load($rootSite)
        $ctx.Load($rootSite.Webs)
        $ctx.ExecuteQuery()
       
        foreach($site in $rootSite.Webs){
           
            #Load sites under each subsite
            $ctx.Load($site)
            $ctx.Load($site.Webs)
            $ctx.ExecuteQuery()

            Write-Host $site.Url -ForegroundColor Green
           
            #Create object for CSV row           
            $details = new-object PSObject
            $details | add-member -membertype NoteProperty -name "Site URL" -Value $site.Url
            $results += $details

            #Go for subsites if it has child sites
            if($site.Webs.Count -gt 0) {

                $results += Get-AllSites $site.Url $userName $password $domain
            }
        
        }
        $ctx.Dispose()      
       
    }
    catch [System.Exception]
    {
        write-host -f red $_.Exception.ToString()   
    }
   
    return $results
}

#Parameters
$siteUrl = "http://contoso/sites/hr"
$userName = "username"
$password ="password"
$domain="DOMAIN"


#Add Client Object Model Assemblies        
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Call fuction
$path = Get-Location
Get-AllSites $siteUrl $userName $password $domain | export-csv -Path $path\List.csv -NoTypeInformation

Write-Host "Report exported to CSV, please check file on location: $path"

Read-Host

Tuesday, April 14, 2015

Relink InfoPath form using Nintex Workflow

In one of my recent project i wanted to copy InfoPath Form from one library to other- second library InfoPath Form template was exactly similar but included few more fields.

In second library i created workflow and used Update XML action, configure it as below


XPath Query

/processing-instruction('mso-infoPathSolution')

In second text box use PI information as below format.

name="urn:schemas-microsoft-com:office:infopath:LeaveForm:-myXSD-2015-02-27T14-45-21" solutionVersion="1.0.0.821" productVersion="15.0.0.0" PIVersion="1.0.0.0" href="https://contoso/LeaveRequestArchive/Forms/template.xsn"