Joeprakash's Blog

How to migrate SharePoint 2010 List based workflows

Problem Statement:

We have a SharePoint 2010 list on our site and a workflow is associated to that list.

Sometimes, the existing list gets corrupt and we have to replicate the list using the list template saved earlier. Now, the existing workflow does not get associated to the new list and we have to re-create the entire workflow in SharePoint Designer.

Another scenario for associating an existing workflow is when the site is migrated; as, the workflow-list association is broken.

Solution:

Re-creating the entire workflow in SharePoint Designer can be a tedious process.

The alternative to this is to modify the source workflow files to force it to re-attach to the new list.

Note: There should be no schema mismatch between the old and new list.

When a workflow is created in a site for the first time, a Tasks list and…

View original post 304 more words

Displaying SharePoint list from top level or subsite in SharePoint 2010 Data View web part


In SharePoint 2010 Data view web part, there is no direct way to connect to Data Source of a different site in the same site collection.

What do we do when we need to fetch data from a list residing in the top level site or sub site in SharePoint 2010?

The answer to above question that generally crops up is to use a SOAP Service connection data source and connect data view to this data source.

I feel that we should go to this approach if there is nothing possible directly. The overheads in having another data source is that we have to keep updating the data source in case any column in the list is added. Once we update data source, then we need to update the Data view web part accordingly.

If we use default list data source, things would be pretty easier and there is no overhead.

Hence, I digged down in to the code to find out an alternative for this.

The solution is the usage of parameter viz. WebURL.

Pre-requisite: Configure the Data view web part to use List Name instead of List ID

In Data view web part, there is a tag <ParameterBindings> within which we have several <ParameterBinding> tags.

Add one as given below:

<ParameterBinding Name=”WebURL” Location=”None” DefaultValue=”/sites/top-site-name/”/>

There is a tag viz. <SPDataSources> within which we have <Select> tag.

Modify contents within <Select> tag as given below:

<SelectParameters><WebPartPages:DataFormParameter Name=”WebURL” ParameterKey=”WebURL” PropertyName=”ParameterValues” DefaultValue=”/sites/top-site-name/”/>

The same can be applied to InsertParameters, UpdateParameters, DeleteParameters.

Kindly comment if you are unable to follow the updates or face any issues.

How to migrate SharePoint 2010 List based workflows


How to migrate SharePoint 2010 List based workflows

Problem Statement:

We have a SharePoint 2010 list on our site and a workflow is associated to that list.

Sometimes, the existing list gets corrupt and we have to replicate the list using the list template saved earlier. Now, the existing workflow does not get associated to the new list and we have to re-create the entire workflow in SharePoint Designer.

Another scenario for associating an existing workflow is when the site is migrated; as, the workflow-list association is broken.

Solution:

Re-creating the entire workflow in SharePoint Designer can be a tedious process.

The alternative to this is to modify the source workflow files to force it to re-attach to the new list.

Note: There should be no schema mismatch between the old and new list.

When a workflow is created in a site for the first time, a Tasks list and a Workflow History list are automatically created/used by the workflow.

We will be using this concept for the migration.

Follow the below mentioned three steps in order to associate the workflow with the new list:

Step 1 – Create a Blank Workflow

  1. Using SharePoint designer, connect to your destination site
  2. Create a new list-based workflow called “test” (or any other name), attaching it to your migrated list
  3. Create one condition (e.g. if 1 = 1) and one action (e.g. add comment “hello”)
  4. Save and publish the workflow

Your site will now have a Tasks list and Workflow History list.

Step 2 – Get the List IDs for the new workflow

The list ids are required to configure your migrated workflow.

  1. Using SharePoint Designer, connect to your destination site
  2. In the left navigation page, under Site Objects, select All Files
  3. In All Files list, select Workflows
  4. Select your new workflow that you just created (in this example, “test”)
  5. You should see (at least) four files:
    text.xoml
    test.xoml.rules
    test.xoml.wfconfig.xml
    test.xsn
  6. Right-click on test.xoml.wfconfig.xml and select Open With, Notepad
    Look for the <Association…> tag in the xml:
    <Association ListID=”{770980F2-DA18-4089-96A2-066DF774BEA5}” StartManually=”true” TaskListID=”{DA6A8029-A1BE-4775-9E9B-1558CEA98791}” HistoryListID=”{44B38DD6-B5F1-4BF2-B063-B624DE88A207}”/>
    Record the GUID entries for ListID, TaskListID and HistoryListID.

Step 3 – Update the Existing workflow

  1. Using SharePoint Designer, All Files, Workflows, select your existing workflow
  2. You should again see (at least) four files. Right-click on “<your-workflow>.xoml.wfconfig.xml” and select Open with SharePoint Designer (As XML)
  3. Find the Association tag and very carefully change the GUIDs so that your migrated List IDs are the same as the “test” workflow List IDs
    Association tag
  4. Save the file
  5. Close SharePoint Designer
  6. Open SharePoint Designer again and open your site
  7. Instead of All Files, this time click on Workflows
  8. Select your workflow
  9. Save the workflow
  10. Publish the workflow

Your existing workflow should now be re-associated with the new list.

Reference:

http://gavinmckay.wordpress.com/2011/08/29/howto-move-or-migrate-sharepoint-2010-list-based-workflows-between-sites-and-site-collections/

Client side validation of SharePoint Rich text field


Requirement: Mandatory field validation for SharePoint Rich text field in List form

Hurdles faced: Comparison of the value in the rich text field with an empty string in JavaScript returned FALSE even though there was no text in the rich text field

Approach:

  1. The RTE (Rich text editor) is rendered in the following way in browser
    As can be seen in the above snapshot, the DIV where the data is stored is the second child of the parent div. This is the scenario where no data is inserted in the field
  2. First thing that we tried is to fetch the inner text of this DIV element
    As can be seen, text() returns “” i.e. empty string
  3. Now, we try to compare this with empty string in JS 
  4. As the above returned false, we decide to check the inner HTML present in that DIV
    The inner HTML returned empty paragraph tag. If you observe, there is a space between ‘<’ and ‘/p’.We now try to compare this inner HTML with the empty paragraph tag:

    Even this did not return TRUE
  5. On double clicking the value returned in inner Text and HTML, a space was found to be inserted

  6. On digging deep, this space was found to be a Unicode character inserted by SharePoint viz. ZERO WIDTH SPACE
    “%E2%80%8B” is the value returned on encoding this space using JavaScript
  7. Thus, the conclusion is that we need to compare with this ZERO WIDTH SPACE
  8. One option is to compare the text() with “%E2%80%8B”; but, this will still return FALSE when the focus is on the Rich text field.
    In order cover both scenarios, Regex helps us to replace this Unicode character viz. ZERO WIDTH SPACE with normal empty string viz. “” 
    As can be seen, the Unicode character (\u200B) is used in the Regex for comparison and replaced with empty string
  9. We can compare the replaced value with an empty string to get TRUE as return value

    This is the required SOLUTION

SharePoint Configuration Database in Suspect Mode


Issue:

Unable to load my SharePoint site hosted on a VM. Page threw the error viz. ‘Cannot connect to configuration database’

Resolution (Steps taken):

  1. Observed that ‘SharePoint_Config’ DB was in Suspect mode. In SSMS, I found the Suspect status with SharePoint_Config DB
  2. On restarting SQL services, Recovery status was displayed with SharePoint_Config DB
  3. After the recovery process completed, the DB name was rendered properly in SSMS; but, page still threw the error viz. ‘Cannot connect to configuration database’
  4. After some time, Suspect status had resurfaced on viewing in SSMS. This showed that the DB was still corrupt
  5. In such scenarios, one option would have been to restore the DB with an old backup. In my case, I did not have a backup L
  6. On searching the net, I found few blogs mentioning this issue
    1. http://nikspatel.wordpress.com/2011/03/02/sharepoint_config-suspect-mode-cannot-connect-to-the-configuration-database-error/
    2. http://ahmershahid.wordpress.com/2009/05/25/moss-2007-config-db-in-suspect-mode/
  7. As per the blogs, the SharePoint DB gets corrupt occasionally when the VM restarts untowardly
  8. Script that helped me resolve the issue:
    -- Use the Master database
    Use Master
    
    -- Verify that database has issues
    EXEC sp_resetstatus 'SharePoint_Config'
    
    -- Put the database in emergency mode
    ALTER DATABASE SharePoint_Config SET EMERGENCY
    DBCC checkdb('SharePoint_Config')
    
    -- Set the database in single user mode
    ALTER DATABASE SharePoint_Config SET SINGLE_USER WITH ROLLBACK IMMEDIATE
    
    -- Repair the database with data loss
    DBCC CheckDB ('SharePoint_Config', REPAIR_ALLOW_DATA_LOSS)
    
    -- Set the database in multi-user mode
    ALTER DATABASE SharePoint_Config SET MULTI_USER
    
    -- Verify that database is reset
    EXEC sp_resetstatus 'SharePoint_Config'
    
    
  9. PFA: SharePoint_Config_Recovery.sql, SQL script mentioned in the blogs which helped me resolve the issue
  10. Script tries to set the DB in Emergency mode and repair the data loss. This should be applicable to any DB which gets corrupt and goes into Suspect mode

Display random items using XSLT in Data view web part


This article describes how to display random items using XSLT in Data view web part in SharePoint 2010. I assume that the reader is aware of how to add a data view web part and read items from SharePoint list or library.

Requirement:

Generally on a web site, we would like to display the head shots of all people associated with the organization. In addition, we do not want the people icons displayed to be in the same order always. We would like visitors to see the order of people icons displayed to be refreshed every time the page is hit.

Pre-requisites:

Knowledge of using Data view web part connected to a list/ library in SharePoint 2010

Solution:

Create an asset library

1. Create an asset library
2. Upload the requisite images of same dimension in this library

Insert Data View web part using SharePoint Designer


1. Insert a Data View web part using SharePoint Designer
2. Connect this web part to the asset library created above
3. Set the data view to display all items from the library

How to randomize the order of the items

1. XSLT has a function viz. ddwrt:Random
2. The items are traversed using for-each in XSLT code as below:

<xsl:for-each select="$Rows">
    <xsl:call-template name="dvt_1.rowview" />
</xsl:for-each>

3. Add ‘xsl:sort’ for the items as shown below:

<xsl:for-each select="$Rows">
    <xsl:sort select="ddwrt:Random(1, $RowCount)" order="ascending"/>
    <xsl:call-template name="dvt_1.rowview" />
</xsl:for-each>

4. In the above code, ‘$RowCount’ refers to the total number of items present in the list
5.  Now, your order of display of items will change each time the page is refreshed
6. You can change the rendering to display images and modify the UI accordingly
7. This will resolve the issue of displaying items in random order using XSLT in Data View web part

“I hope that this post will allow you to resolve the issue of displaying random items from list/ library. Provide your feedback to help me improve my blog :)”

People Presence indicator issue with IE9 in SharePoint 2010


Presence Indicator:

SharePoint 2010 displays presence indicator of the user when he is signed in to Lync.

In XSLT we can just use <xsl:value-of select=”@FieldName” disable-output-escaping=”yes”/> inorder to render the value of people picker entry on the page; provided, the column type is set to ‘Name with presence enabled’.

Image

ISSUE:

In IE9, this presence indicator does not render due to issues with the internal JS of SharePoint.

FIX:

We need to override a function to get this fixed. On your master page use the following code snippet to resolve the above rendering issue.

<script type=”text/javascript” defer=”defer”>

// replace IE Function:

var ProcessImnMarkers = function ()

{ ULSxSy:;
var i ;
for (i = 0; i < imnMarkerBatchSize; ++i)
{
if(imnCount === imnElemsCount)
{ return; }

IMNRC(imnElems[imnCount].getAttribute(‘sip’),imnElems[imnCount]);
imnCount++;
}

setTimeout(“ProcessImnMarkers()”, imnMarkerBatchDelay);
};

</script>

Voila!

The presence indicator should now render in IE9 🙂