Why Wait for Document to be Unlocked by Document Editor Sucks

If you are using the SharePoint Designer action wait for document to be unlocked by document editor, you may be aware of it’s shortcomings.  Like what?  Well, if you submit a form or document to the library, this action fires.  If the form/document happens to be a little slow getting to the library, the workflow will pause for another 5 minutes!  ¡No bueno! 

What I did to get around this was, write a little inline PowerShell script as my first action in the Workflow.  The script loops every 5 seconds to see if the form/document has been unlocked.  5 seconds vs 5 minutes, there is a large difference.

How? If you don’t already have the iLove SharePoint Workflow Actions installed, do it! The actions can be downloaded here: http://ilovesharepoint.codeplex.com/ .  (read the documentation)

Once installed, modify your Worflow or create a new one. I replaced the lame Wait for Document to be Unlocked by Document Editor with a Execute PowerShell action. The PowerShell code is below.


if(-not(Get-PSSnapin | where { $_.Name -eq "Microsoft.SharePoint.PowerShell"}))
{
 Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$site = Get-SPweb "http://sharepointed.com/sites/taco/"
$mList=$site.Lists["The Library"]
$item = $mList.GetItemById([<strong><span style="text-decoration: underline;">%Current Item:ID%</span></strong>])

$Lock = $item.File.LockType

while($Lock -ne "None")
 {
 start-sleep -s 5
 $Lock = $item.File.LockType
 }

Please notice the line $item = $mList.GetItemById([%Current Item:ID%]), Current Item: ID is the ID of the item that started the workflow.  This is key to Workflow action working!

*update*

It’s also a good idea to modify your default view and other views to only show workflow items that have a completed status.  How?  Edit the view, scroll down to the Filter section, select the column that has your workflows name in it.  The next drop down should be ‘is equal to‘ and the text box, input the number five 5.  5 represents the Completed workflow status.

SharePoint Completed Workflow Status

SharePoint Completed Workflow Status

Monitor Content Database Size with Powershell

Simple question.
How large are the content databases?

To solve this, I created a list in Central Administration, and wrote a quick PowerShell script to update the list with my Content Database size(s).

List Name: Content db Size
List Columns: Title, db name, db size (Type = Single line of text)
View: Show Title, db name, db size

PowerShell Script:

if(-not(Get-PSSnapin | where { $_.Name -eq "Microsoft.SharePoint.PowerShell"}))
{
      Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$adminwebapp = Get-spwebapplication -includecentraladministration | where {$_.IsAdministrationWebApplication}

$siteUrl = $adminwebapp.Url
$listName = "Content db Size"
$spSite = new-object Microsoft.SharePoint.SPSite($siteurl)
$spWeb = $spSite.OpenWeb()
$spList = $spWeb.Lists[$listName]
foreach ($item in $spList.items) { $deaditem = $splist.GetItemById($item.ID); $deaditem.Delete(); }

$webapps = Get-SPWebApplication
foreach($webapp in $webapps)
{
    $ContentDatabases = $webapp.ContentDatabases
    foreach($ContentDatabase in $ContentDatabases)
    {
    $ContentDatabaseSize = [Math]::Round(($ContentDatabase.disksizerequired/1GB),2)
	$addItem = $spList.Items.Add()
	$addItem["Title"] = $webapp.DisplayName
	$addItem["db name"] = $contentdatabase.name
	$addItem["db size"] = $contentdatabasesize
	$addItem.Update()
    }
}

$spWeb.Dispose()

The script is doing the following actions:
Truncate the Content db Size list.
Looping through all the Web Apps.
Updating the Content db Size list with the Web App name, db name, and size.

Taking this to the next level:
Update the existing list item, opposed to truncating the entire list.
Setup a workflow to email you if a db size is greater than X.

*update*

What if you want to get all the Site Collections in a Content Database?
 

$sites = Get-SPSite -Limit All  -ContentDatabase YourContentDatabaseName

foreach($site in $sites)
{
	$siteSize = [math]::round(($site.usage.storage/1GB),2)
	Write-Host $site.url "--" $siteSize
}

Use Links List to Add Navigation to a Page

Say you have a lot of lists and libraries on your site. How do you easily allow people to navigate your site?

What I’m going to do is, create a List, then use web parts on a page to display the list items in groups.

Create a new Links List
Site Actions –> View All Site Content –> Create –> Links
I named my list Navigation.
Once you have created the list, click on the List tab in the ribbon, then select Create Column.
Column name: Category
Require that this column contains information: Yes
Type each choice on a separate line: Fruit and Veggie (you can enter whatever you want)
Click OK.

Once you have setup the list, add a few items to it.
Simply click +Add new link to add an item.

As you can see here, I’m adding a link to my Onion library, description is Onion, and my Category is Veggie.

I went ahead and added two more items to the list.

In the next step, I’m going to create a new web part page to house the navigation. You can use an existing page and skip this step.

To create a new page
Site Actions –> View All Site Content –> Create –> Web Part Page
Click Create, then on the next page, you will want to give your page a name.
Then select the layout you want to use. For step, I select the first layout listed.
Lastly, select a Save Location for your page and click Create.

When the page opens, you will have some web part zones on the page. These zones are used to add web parts to.
Click Add a Web Part, the ribbon will change to display the available web parts. In the Categories section, select Lists and Libraries, then select Navigation (or whatever you named your Links List). Once selected click Add.

Now we want to edit the web part to filter what is displayed, and change the web part name.
To edit the web part, move your mouse over the top right corn of the web part. You will then see a small triangle appear, click on it. This will bring up the options menu for the web part. To edit the web part, click Edit Web Part.

Look at the right side of your screen, you should see the web part proprieties window.
In the Appearance section, I changed the name to Veggie.

Scroll up a little.

In the List Views section, click on Edit the current view. When the Edit View page opens you will see an option that allows you to add or remove columns from the web parts view, and others. Scroll down to the Filter section. The first dropdown box, select the Category field, leave the next dropdown to is equal to, and then type in the next box the value you want to filter by.

Scroll to the bottom, and click OK
Once you return to the page, you will now see that the web part is filtered by the value we entered into the filter section of edit view page.

To add another web part, edit the page again, and follow the above steps to filter by another value.

Final product.

Let me know if you have any questions.

Failed to cache field with id “{ }”, overwrite=0

Workflow failed with this error:
Failed to cache field with id “{blah-dae2-4908-80cd-blah}”, overwrite=0

In my list (A) I had a lookup column pointing to another list (B). In B, I had updated a field from Single line of text to Multiple lines of text. The workflow did not like this update. Once I recreated the field as a Single line of text, the workflow started working.

Coercion Failed: Unable to transform the input lookup data into the requested type.

SharePoint Workflow error:
Coercion Failed: Unable to transform the input lookup data into the requested type.

Using a workflow, I was trying to set the value of a Lookup field. Where I went wrong was, setting the Lookup field to a field other than the ID column of the Lookup List.

What??

Quick example:
Created two lists.
Taco and Taco Topping.

Taco Toppings fields: Title, Meat, Cheese, Salsa

In the Taco list, I added a Lookup field to Taco Topping, also adding Meat, Cheese, and Salsa fields.

Now for the workflow.

On the Taco list, create a new SharePoint Designer workflow.

The workflow will contain the following actions: Set Workflow Variable and Update List Item

First we will create the variable
click inside of Step 1, from the ribbon click on Action, then find Set Workflow Variable.
Once it’s added to the workflow step, click on blue workflow variable text.
I named my variable Taco ID and set the type to Number.

Next click on the blue value text.

Here I’m querying the Taco Topping list for the ID field, and filtering by the Title column of the Title fields of Taco and Taco Topping. Think of this a simple SQL select statement with a where clause. Select ID from Taco Topping where Title = Current Item: Title

Next we will add the Update List Item action.
Click below the Set Variable action, then add the Update List Item from the Action button in the ribbon.
Click on the blue this list text.

Here I’m updating field T to the ID from workflow variable Topping ID.
This is what will drive updating our Taco list to the toppings from Taco Topping.

Your workflow should now look like this.

Publish the workflow, all done!

*Be sure to change your workflow settings (in the ribbon) if you want the workflow to run when a new item is added or changed.*

Get The Size of a Document Library

“How large is my Document Library”

This was an odd one to crack. For reporting reasons, our team wanted to track the item count and size growth of a Document Library. Sound easy?

if(-not(Get-PSSnapin | where { $_.Name -eq "Microsoft.SharePoint.PowerShell"}))
{
      Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$SPsite = Get-SPsite "http://www.sharepointed.com/sites/taco/"

$dataTable = $SPsite.StorageManagementInformation(2,0x11,0,0)
foreach($x in $dataTable.Rows)
{
	if ($x.LeafName -eq "MyTacoLibrary" -and $x.Directory -eq "sites/taco")
		{
			$LibSize = [Math]::Round(($x.Size/1GB),2)
			Write-Host $LibSize
		}
}

Thanks you Jon for guiding this script.

Use PowerShell to Export a List of My Sites

How many My Sites (MySites) are currently enabled in my Farm?

if(-not(Get-PSSnapin | where { $_.Name -eq "Microsoft.SharePoint.PowerShell"}))
{
      Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$site = Get-SPsite "http://mysite.sharepointed.com/"
$spWebApp = $site.WebApplication

$log = "c:\test.txt"

foreach($site in $spWebApp.Sites)
{
    $site.url |	Out-File $log -Append
    $site.Dispose()
}

load the powershell snapin.
get the Web App hosting your My Sites.
set a variable to where you want the script to output the results to.
loop through all the sites in the Web App, and output them to your text file.

People search not working

The People scope in Central Administration was showing 0 ( zero ) items, but my Number of User Profiles in Manage Profile Services was showing plenty of profiles.

First I looked at the scope to make sure it was correct.

Scope Rule Type: Property Query

Property Query: urn:content-class:SPSPeople 

Behavior: Include

Next, I looked at the User Profile Service (Central Admin –> Manage Service Applications) or (http://yourCentalAdminURL/_admin/ServiceApplications.aspx).  I wanted to make sure the same account that was crawling all my data had access to this service.   Select the first User Profile Service item, then click on Administrators in the ribbon.  Your Default content access account should be listed here with Retrieve People Data for Search Crawls permissions.

If your Default content access account is not listed in the Administrators list, add the account and give it Retrieve People Data for Search Crawls permissions.

Where I can find my Default content access account?

Central Administration –> Manage service applications (under Application Management) –> click on Search Service Application.  There you should see your System Status web part, and listed will be Default content access account.

my sharepoint is slow

Recently received an email from a user that basically said “my SharePoint is slow.”

The user sent me a link to the Form Library they were working with.  I clicked on link and it took roughly two minutes for the page to open.  Long story short, the user had changed to View to display 2,000 items at a time.

I updated the View to return 50 items, and now “my SharePoint is fast.”