Virtual Business Card


A Jack of all trades is a master of integration, as such an individual who knows enough from many learned trades and skills to be able to bring their disciplines together in a practical manner, and is not a specialist but can be an expert in many fields. Such a person is known as a polymath or a renaissance man; a typical example is someone like Leonardo da Vinci.

Tuesday, October 11, 2011

JQuery to Open Links in a New Window

The code below is very useful when displaying a SharePoint page using a minimalistic masterpage in an IFrame of CRM 2011 dashboards. So instead of the page opening inside the IFrame of CRM 2011, it will open a new page. Add code in the script tag:

$(document).ready(function() {
$('a').attr('target', '_blank')
});

Increasing Debug Time in Sharepoint 2010


If you’re developing for SharePoint 2010 the Application Pool has a setting called Ping Maximum Response Time with a default value of 90 seconds. In effect, this means that debugging your Web Part, Page, etc. in SharePoint 2010 will only work for 90 seconds and then you get this:

"The web server process that was being debugged has been terminated by Internet Information Services(IIS). This can be avoided by configuring Application Pool ping settings in IIS. See help for further details."

The error is really self explanatory and very helpful. To resolve this:


- Click on Start->run->inetmgr

- Locate your application pool and select Advanced Settings on the menu on the right

- Modify the value of Ping Maximum Response Time (Seconds)


You can also increase the value for future Application Pools via Set Application Pool Defaults by selecting the root node of Application Pools in IIS.

Accessing Workflow Status in a List

I have a CAML Query below that queries a list where the workflow for an item is not cancelled.  There's an extra column in the list called Recruitment Workflow which is of type WorkflowStatus.  This column is somehow automatically added by SharePoint.  I tried to query using CAML using the query below:
Note That I'm using the Internal Name for Recruitment Workflow Column in this query.
<Query>
       <Where>
                  <Neq>
                          <FieldRef Name="Recruitm" />
                          <Value Type="WorkflowStatus">Canceled</Value>
                 </Neq>
         </Where>
</Query>

Weird thing is I'm not getting any results.
I also tried to query everything to test my insanity and query and test if the column exsist:
foreach (SPListItem item in recruitmentrequests)
{
                item[“Recruitment Workflow”] =
               ….
}
It fails on  the underlined code and I got the error


item["Recruitment Workflow"]' threw an exception of type 'System.ArgumentException'
    base {System.SystemException}: {"Value does not fall within the expected range."}
    Message: "Value does not fall within the expected range."
    ParamName: null

I also replaced the code with  item[“Recruitm”] =

and I still got the error above.  I also tried item["Recruitment_x0020_ Workflow"];

and it generates an error saying that column does not exist.
I also checked via code if that column exists using item.Fields["Recruitment Workflow"] and it can retrieve it.

So this is really puzzling me.  The column is there but I cannot query it to get its value using CAML or .NET code.


It looks like accessing a workflow status is a special case and cannot be accessed via SPListItem["WorkflowStatusColumnName"].  You can access it using the snippet below:

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
// This is Console Application //
SPSite site = new SPSite("http://sharepoint-site/");
SPWeb web = site.OpenWeb();
foreach (SPList list in web.Lists)
{
    foreach (SPListItem item in list.Items)
    {
        foreach (SPWorkflow workflow in item.Workflows)
        {
            try
            {
                Console.WriteLine("item url : " + item.Url);
                Console.WriteLine("workflow name : " + list.WorkflowAssociations[workflow.AssociationId].Name);
                Console.WriteLine("workflow status : " + item[list.WorkflowAssociations[workflow.AssociationId].Name]);
                Console.WriteLine();
            }
            catch (ArgumentException)
            {
                //ArgumentException is throwed if the workflow is not exist in the list column.
                Console.WriteLine("Workflow name : {0} is already not exist in List title : {1}.",
                    list.WorkflowAssociations[workflow.AssociationId].Name, list.Title);
            }
        }
    }
}