Wednesday 9 December 2015

There are no items to show in this view of the list. Customize default message using content Editor Webpart in SharePoint

When a list or library does not have any items in it, a message will display in the view as in the screenshot.


If you want to customize the message, just add the below scripts in content Editor web part and Save the page. 

Go to the page where you have placed the list which you want to modify, Site Action-> Edit Page->select add a web Part->choose Content Edit Web Part. then you need to add the following sample code in Source Edit.

<script>
function ChangeEmptyLibraryMessage()
{
  var a = document.getElementsByTagName("TD")
  for (var i=0;i<a.length;i++)
  {
    if (a[i].className=="ms-vb")
    {
      a[i].innerHTML = "There are no items to display here.";
    }
  }
}
_spBodyOnLoadFunctionNames.push("ChangeEmptyLibraryMessage") 
</script> 

The shaded message will show in the place of default message.


The above script will be for that particular page where you have placed it.

If you want to change the default message in all list in the site, open the Default.apsx page in SharePoint Designer search for “There are no items to show in this view of” text in the code and replaced the text with the message you want to display. This will work for all lists and calendar events.

Wednesday 2 December 2015

Designer workflow is not sending email to SharePoint group


I created a workflow in SharePoint Designer, which has to send an email when an item is added in a list. It works as expected when the email assign to a user. However, if I give SharePoint group instead of user, it does not send email to the members of the group.

First make sure that the group has at least “read only” access to the entire site.

Go to Site Settings -> People and groups -> Your group settings -> select an option which says that the members in this group are accessible to everyone.



Tuesday 24 November 2015

You do not have permission to perform this action or access this resource. SharePoint 2013 workflow cancelled

Recently I had come up with an issue regarding permission of workflow and workflow got cancelled.

"Access denied. You do not have permission to perform this action or access this resource." SharePoint 2013 workflow cancelled.



By default, workflow does not have permissions to access the app request catalog. Catalog lists in SharePoint require owner (full control) permissions. Workflows generally run at permission level equivalent to write. 

To solve this, workflow should get elevated permissions. If you have properly configured the SharePoint 2013 Workflow platform and workflow is created through designer just activate the below feature from site settings.

Activate site feature "Workflows can use app permissions"
Site actions > Site Settings > Site features > Workflows can use app permissions
Workflow started working as usual.
Hope this helps....


Tuesday 12 May 2015

PowerShell Script : Change content type for all documents in a library

I had come up this requirement after migration. The old migrated library is populated with thousands of files having the default content type set to ‘Document’. All the documents now need to be assigned a specific content type.
If we have a large library Powershell is the easy way to change the content type. Before you run the script, make sure the new content type is associated with the library.
The script below sets up a function which will look at the document library and modify all files associated with the specified content type to a different one.

'Drop Off Library' is my library name and want to update all files associated with 'Document' content type to 'Techsheet'.

if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}
$webUrl = "http://server:portno/sites/yoursite"
$web = Get-SPWeb $WebUrl
$list = $web.Lists["Drop Off Library" #Library Name
$oldCT = $list.ContentTypes["Document" #Old Content Type Name
$newCT = $list.ContentTypes["Techsheet" #New Content Type Name
$newCTID = $newCT.ID
write-host $newCTID
for($i=0; $i -le $web.Lists.Count; $i++)
    {
    foreach($item in $list.items[$i])
        {
        if ($item.ContentType.Name -eq $oldCT.Name)
            {
                 #Check the check out status of the file
                if ($item.File.CheckOutType -eq "None")
                {
                    #Change the content type association for the item
                    $item.File.CheckOut()
                    write-host "Resetting content type for file" $item.Name "from" $oldCT.Name "to" $newCT.Name
                    $item["ContentTypeId"] = $newCTID
                    $item.Update()
                    $item.File.CheckIn("Content type changed to " + $newCT.Name, 1)
                }
            }
        }
    }
$web.Dispose() 


Thursday 5 March 2015

Bulk Indexing documents to Multiple Libraries using Powershell

Suppose we have a Document Library with large no. documents and we want to update the metadata which is kept in an excel file from local drive using PowerShell. Like this we have Multiple document Libraries and Metadata templates. Below is the process to iterate through each document library with its excel templates.
Steps

As all of you know there is no direct way to update metadata from Excel. So we have to convert excel to CSV format. And avoid space in column names in the CSV file.
1. Save as excel file to CSV format
2. Create a folder structure in windows drive to store the list templates in CSV format.


3. Create a list in SharePoint to store the folder path for each CSV template corresponding to each Library. Here the List name is 'IndexList'
4. Map the column names such as LibraryName, LibraryUrlName and TemplatePath in the script
5. Map the column names from CSV to the corresponding column names from SharePoint Library in the script.


if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null

{

Add-PSSnapin Microsoft.SharePoint.PowerShell

} 

$url = "http://sitename:portno/"

$OpenWeb = Get-SPWeb $url

$DocumentIndexing = $OpenWeb.Lists["IndexList"]

ForEach($item in $DocumentIndexing.Items)

{

$docLibraryName = $item["LibraryName"]

$docLibraryUrlName = $item["LibraryUrlName"]

$localFolderPath = $item["LinkTitle"]

$docLibrary = $OpenWeb.Lists[$docLibraryName]

Write-Host $localFolderPath

$file = Get-Content "$localFolderPath"

#Open file

function Update-SPList()

{

$data = Import-Csv $localFolderPath

$OpenWeb = Get-SPWeb $url

$folder = $OpenWeb.getfolder($docLibraryUrlName)

Write-Host $folder

foreach($row in $data)

{

#CAML query compares LinkFilename in the Library and Name Column in the CSV

$spQuery = New-Object Microsoft.SharePoint.SPQuery

$camlQuery = '<Where><Eq><FieldRef Name="LinkFilename" /><Value Type="Text">'+ $row.Name +'</Value></Eq></Where>'

$spQuery.Query = $camlQuery

$listItems = $docLibrary.GetItems($spQuery)

foreach($item in $listItems)

{

# List Out all column names from all CSV Templates of without Duplication and pass the value to Library columns.

   Write-Host "Updating" $item["LinkFilename"] "with" $row.Name

   $item["Content Type"] = $row.Document_Category

   $item["DATE_x0028_MM_x002f_YY_x0029_"] = $row.DATE

   $item["Location"] = $row.Location

   $item["Licence_x0020_No"] = $row.Licence_No

   $item["Center"]=$row.Center

   $item["Ticket"]=$row.Ticket_No

   $item["Amount"]=$row.Amount

   $item["Course"]=$row.Course

   $item.Update()

}

#Clear all rows except the CSV column Names

(Get-Content $localFolderPath |  Select -First 1) | Out-File $localFolderPath 

}
}

Update-SPList

if($OpenWeb)

{

$OpenWeb.Dispose()

}

}


Once it is updated the rows will be automatically deleted from the CSV template .

Thursday 5 February 2015

How to update a SharePoint list column through Powershell

PowerShell Script for updating SharePoint List Column

if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)
{
 Add-PSSnapin Microsoft.SharePoint.PowerShell
}
 
#Script settings
 

$web = Get-SPWeb https://sitename:port/

$list = $web.Lists["ListName"]

foreach ($item in $list.Items)
{
$item["Column1"] = "Text";
$item["Column2"] = "Text";
$item.Update();
}

write-host "Success"
 #Dispose web
 
$web.Dispose()

If it is a large List we can update the List column batch wise. Below is the script for updating share point list item batch wise

if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)

{
  Add-PSSnapin Microsoft.SharePoint.PowerShell


}
 
#Script settings
 
 

$web = Get-SPWeb https://sitename:port/

$list = $web.Lists["Tasks"]

$spQuery = New-Object Microsoft.SharePoint.SPQuery

$spQuery.ViewAttributes = "Scope='Recursive'";

$spQuery.RowLimit = 100

$caml = '<OrderBy Override="TRUE"><FieldRef Name="ID"/></OrderBy>'

$spQuery.Query = $caml

do

{
$listItems = $list.GetItems($spQuery)

$spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition

foreach($item in $listItems)

{
$item["Column1"] = "Text";

$item["Column2"] = "Text";
$item.Update();

}

}
while ($spQuery.ListItemCollectionPosition -ne $null)

write-host "Success"
#Dispose web
$web.Dispose()

 

Hope this helps..