Saturday, April 3, 2010

Concept of Features in SharePoint 2007

I always wanted to know why Features are called so in SharePoint 2007. Infact, many people asked me the same thing. After some research in Google, I found a link which explains this.

http://sharepoint.microsoft.com/blogs/mike/Lists/Posts/Post.aspx?ID=7

Tuesday, March 16, 2010

Difference between ArrayList And HashTable And Dictionary

I was always keen to know the difference between ArrayList,HashTable & Dictionary. Here it goes.

An ArrayList behaves just like an array, except that it will dynamically expand and contract when you add/remove elements to it. A HashTable is useful when you want to lookup objects indexed by a 'key' value. It also dynamically expands and contracts but doesn't impose an order on the elements like an array does. Put a different way: you index elements in an ArrayList with a numeric index, you index elements in a HashTable with a key. Such a key is often a string.

A Dictionary is a hash table.Dictionary is a generic type, Hashtable is not. That means you get type safety with Dictionary, because you can't insert any random object into it, and you don't have to cast the values you take out.

Thanks to the following links.

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/84b8d2a1-e84d-446a-94bb-4ec54d3b38cf

http://stackoverflow.com/questions/301371/why-dictionary-is-preferred-over-hashtable-in-c

Wednesday, March 10, 2010

Displaying Attachments in DataView

Normally attachments don't show up in a DataView webpart in SharePoint Designer. To display the attachments, add the following lines in your DataView.

<SharePoint:AttachmentButton ControlMode="Edit" Enabled="true" ItemId="{@ID}" runat="server" Visible="false"/><SharePoint:AttachmentsField ControlMode="Display" ItemId="{@ID}" EnableViewState="true" FieldName="Attachments" runat="server"/>

Thanks to the following link.
http://dbweb.sbisite.com/blogs/bf/Lists/Posts/Post.aspx?ID=19

Monday, March 8, 2010

Cascaded Dropdown in Sharepoint using jQuery

We had to achieve the functionality of Cascaded Dropdowns in SharePoint 2007 Custom List Form web part without custom code. Thanks to the following link which helped in achieving the same

http://spservices.codeplex.com/wikipage?title=$().SPServices.SPCascadeDropdowns&referringTitle=Documentation

Tuesday, March 2, 2010

Dealing with SharePoint Lookup DropdownList with more than 20 items

This has been nagging for so long. Whenever you have a dropdownlist column pulling values from a lookup list with more than 20 items, SharePoint makes it like an editable dropdown. To get around this issue, I found a couple of excellent links which explain the solution.

http://www.sharepointings.com/sharepoint-lookups-over-20-items-solution/

http://boris.gomiunik.net/2009/10/sharepoint-lookup-field-how-does-it-work-and-how-to-add-javascript-event-handler-function-to-it/

Friday, February 19, 2010

Required Fields in SPD Workflow

There is a strange and surprising thing happening with SPD workflows. Suppose a workflow gets triggered on a new item creation or an item modification. Consider the scenario where this workflow creates a new item in another list which has only Title as the mandatory field. After developing your workflow, you go to the target list (where you have to create a new item through workflow when a new item is created or when an existing item is modified) and changed a few fields as Required, surprisingly, the workflow does work without any issues. Only thing is that when a new item is created, the newly changed mandatory fields are not filled by the workflow. But there is a caveat. Once you have to make some changes to the workflow and compile it again, then it won't allow you to do so until all the required fields have been filled.

Tuesday, February 16, 2010

Hide Delete Item Option in Form Toolbar of Custom List Form using SPD

To Hide the Delete Item option from the Form Toolbar using Javascript in SPD, use the following javascript function

function HideDeleteItem()
{
var aList=document.getElementsByTagName("a");
for(i=0;i {
if(aList[i].innerHTML=="Delete Item")
{
aList[i].parentElement.parentElement.style.display="none";
}
}
}

This can also be achieved using jQuery.

$(document).ready(function() {
$(”td.ms-titlearea”).hide();
$(”a[title='Delete Item']“).parent().parent().parent().hide();
$(”td.ms-separator:nth-child(4)”).hide();
});

The advantage of using this jQuery is that it also hides the separator whereas the other normal function doesn't help to achieve this.

Remove {generate-id()} from a Custom List Form using SPD

I created a custom aspx page in SPD and added a Custom List Form web part in it for the Edit item. I assigned some id attributes to some rows in it. As soon as I saved it, I noticed that SPD is appending a {generate-id()} value to it and upon rendering, the assigned id was appended with some characters like ID0EAAA. Because of this, I was having some issues in referring these rows in Javascript. Upon googling, I found an excellent article which explains how to get rid of these.

http://blog.metrostarsystems.com/2007/09/14/how-to-remove-generate-id-from-a-customized-form/

Monday, February 15, 2010

Form OnSubmit & Body OnLoad for a Custom List Form in SPD 2007

We know that in SharePoint, every page is associated with a master page. So we will not have a <Form> tag in it. So it becomes difficult to capture OnSubmit event. But the following post gives a very good explanation on how to achieve this.

http://edinkapic.blogspot.com/2007/10/add-javascript-date-validation-into.html

To achieve the OnLoad event for the <Body> tag, use the following function call

_spBodyOnLoadFunctionNames.push("ExecuteMyFunctionOnLoad");

Thanks to the following link

http://meherkanthch.blogspot.com/2009/01/how-to-add-onload-javascript-event-in.html

Hide Delete Item from Form Tool Bar of Custom List Form using SPD 2007

To hide the Delete Item option from the Form toolbar of a Custom List Form using SharePoint Designer 2007, use the following Javascript in the <Body> tag's OnLoad event.

function HideDeleteItem()
{
var aList=document.getElementsByTagName("a");
for(i=0;i {
if(aList[i].innerHTML=="Delete Item")
{
aList[i].parentElement.parentElement.style.display="none";
}
}
}

OR

use the following lines of jQuery in a javascript function.

$(document).ready(function() {
$("td.ms-titlearea").hide();
$("a[title='Delete Item']").parent().parent().parent().hide();
$("td.ms-separator:nth-child(4)").hide();
});

Note: Download and refer a copy of the latest jQuery script file for this to work.

Enable Attachments in Custom List Form in Edit Mode in SPD 2007

Whenever we have a custom list form web part in an aspx page (in new/edit/display mode), the "Attach" link doesn't work. It gives an error. Refer the following Microsoft KB article for the error and its resolution.

http://support.microsoft.com/kb/953271

Attachment Required Validation for Custom List Form in SharePoint Designer 2007

I have a Custom List Form for Edit Item in a custom aspx page developed using SharePoint Designer. There was a requirement in this. There should be a check for attachments,i.e. attachments should be made mandatory. This had to be achieved through Javascript. The following function helped in achieving the same. Note: This function should be called in the OnSubmit event of the form. Also, don't change the
id "idAttachmentsTable"


function CheckForAttachments()
{
var elm = document.getElementById("idAttachmentsTable");

if (elm == null || elm.rows.length == 0)
{
//document.getElementById("idAttachmentsRow").style.display='none';
alert("Please attach Documents");
return false ;
}
else { return true ;}
}

Thursday, February 11, 2010

Adding Javascript events to SharePoint List Form Fields for Edit Item

The scenario is something like this.

I am trying to do some javascript validation in my Custom List Edit form. I have a List Form field of Choice type. I want to associate this field with some custom javascript function. This javascript function will toggle the visibility of another List Form field of Person or Group type and clear its value, based on the Choice field selection.

For example, there is a Decision field of Choice (Dropdown) type in an aspx page with Custom List Form web part. There is a Reviewer field of Person or Group type. Based on the selection of the Decision, the Reviewer field's visibility should be toggled and also the value in that field should be cleared.

This was achieved in the following way. Lets say the Decision values are Open, Approved and Rejected. The Reviewer field should be shown only if the Decision is Approved, else it should be invisible and should not have any value in it.

Call a javascript function in the <Body> tag's Onload event in the aspx, say Test().
The Test function would be something like this.

function Test()
{
getField('select','Your_Field_Name').onchange = function() {ShowHideReviewer()};
}

Now lets see the functions getField() and ShowHideReviewer().


function getField(fieldType,fieldTitle)
{
var docTags = document.getElementsByTagName(fieldType);
for (var i=0; i < docTags.length; i++)
{
if (docTags[i].title == fieldTitle)
{
return docTags[i]
}
}
}

Note: Make sure you initially give an id attribute (say,trReviewer) to the <tr> containing the Reviewer field and set its style="display:none".

function ShowHideReviewer()
{
var ddlDecision = document.getElementById('ID of the rendered Decision field');
var trReviewer = document.getElementById('ID of the rendered trReviewer');
var reviewer = document.getElementById('ID of the rendered Person or Group field');

if(ddlDecision != null)
{
if(ddlDecision.value == "Open" || ddlDecision.value == "Rejected")
{
if(trReviewer != null)
{
trReviewer.style.display = 'none';
reviewer.innerText = "";
}
}
if(ddlDecision.value == "Approved")
{
if(trReviewer != null)
{
trReviewer.style.display = 'block';
}

}
}

Thanks to the following link for a hint.
http://webborg.blogspot.com/2008/04/add-functions-and-events-to-sharepoint.html

There were a few more requirements.

I had a Region field which was of lookup type. Also a few more MultiPicker look up fields were there for Countries, which should show up based on the selection of the region. Again, as already mentioned, all the country values are lookups. There were 4 possibilities. Americas, ASPAC, EMEA and Global. These are lookup values from a list.These have been shown using a RadioButtonList control on the Custom List Form web part (EditItem) of a Custom aspx page. As mentioned earlier, the Countries for these regions were to be shown based on the selection of Region. Now comes the actual scenario. The user would select a Region. Then the corresponding Countries dropdown will show up and the user would move(add) the desired countries from the Available List to the Selected List. Now the user changes his mind and selects some other Region, so the Countries pertaining to that Region start showing up. Now when he clicks OK, the countries selected in the previous case should get cleared and shouldn't get saved. But it gets saved. We need to get around this issue. This was achieved as follows.

First of all, hide the Regional lookup field, by setting its style="display:none", for the row(<tr>) containing that field. Then add a <asp:RadioButtonList> server control within the same row and manually add the regions as its list items. Once this is done, give an id attribute to all the rows containing the Country Fields. Once this is also done, use the two javascript functions given below to achieve the results.

Note: Call the ToggleRegions function in the OnClick event of the RadioButtonList control and the ClearCountries function in the OnSubmit event of the form.

function ToggleRegions()
{

var trAmericas = document.getElementById('trAmericasID0EAAA');
var trASPAC = document.getElementById('trASPACID0EAAA');
var trEMEA = document.getElementById('trEMEAID0EAAA');
var region = document.getElementById('g_3b8f6f28_7c1c_4ba3_b81c_7a4e9e816ed3_ff4_1_ctl00_Lookup');

var rBtnAm =document.getElementById('g_3b8f6f28_7c1c_4ba3_b81c_7a4e9e816ed3_RadioButtonList1ID0EAAA_0');
var rBtnASPAC =document.getElementById('g_3b8f6f28_7c1c_4ba3_b81c_7a4e9e816ed3_RadioButtonList1ID0EAAA_1');
var rBtnEMEA =document.getElementById('g_3b8f6f28_7c1c_4ba3_b81c_7a4e9e816ed3_RadioButtonList1ID0EAAA_2');
var rBtnGlobal =document.getElementById('g_3b8f6f28_7c1c_4ba3_b81c_7a4e9e816ed3_RadioButtonList1ID0EAAA_3');


if(rBtnAm.checked)
{
region[1].selected = true;
trAmericas.style.display = "block";
trASPAC.style.display = "none";
trEMEA.style.display = "none";
}

if(rBtnASPAC.checked)
{
region[2].selected = true;
trAmericas.style.display = "none";
trASPAC.style.display = "block";
trEMEA.style.display = "none";
}

if(rBtnEMEA.checked)
{
region[3].selected = true;
trAmericas.style.display = "none";
trASPAC.style.display = "none";
trEMEA.style.display = "block";
}

if(rBtnGlobal.checked)
{
region[4].selected = true;
trAmericas.style.display = "none";
trASPAC.style.display = "none";
trEMEA.style.display = "none";
}
}

function ClearCountries()
{
var rBtnAm =document.getElementById('g_3b8f6f28_7c1c_4ba3_b81c_7a4e9e816ed3_RadioButtonList1ID0EAAA_0');
var rBtnASPAC =document.getElementById('g_3b8f6f28_7c1c_4ba3_b81c_7a4e9e816ed3_RadioButtonList1ID0EAAA_1');
var rBtnEMEA =document.getElementById('g_3b8f6f28_7c1c_4ba3_b81c_7a4e9e816ed3_RadioButtonList1ID0EAAA_2');
var rBtnGlobal =document.getElementById('g_3b8f6f28_7c1c_4ba3_b81c_7a4e9e816ed3_RadioButtonList1ID0EAAA_3');
var Countries_AMC = document.getElementById('g_3b8f6f28_7c1c_4ba3_b81c_7a4e9e816ed3_ff5_1_ctl00_ctl00_MultiLookupPicker');
var Countries_ASPAC = document.getElementById('g_3b8f6f28_7c1c_4ba3_b81c_7a4e9e816ed3_ff6_1_ctl00_ctl00_MultiLookupPicker');
var Countries_EMEA = document.getElementById('g_3b8f6f28_7c1c_4ba3_b81c_7a4e9e816ed3_ff7_1_ctl00_ctl00_MultiLookupPicker');

if(rBtnAm.checked)
{
Countries_ASPAC.value = "";
Countries_EMEA.value = "";
}

if(rBtnASPAC.checked)
{
Countries_AMC.value = "";
Countries_EMEA.value = "";
}

if(rBtnEMEA.checked)
{
Countries_ASPAC.value = "";
Countries_AMC.value = "";
}

if(rBtnGlobal.checked)
{
Countries_AMC.value = "";
Countries_ASPAC.value = "";
Countries_EMEA.value = "";
}

}