Tuesday, October 20, 2009

Coloring Events in SharePoint calendar

Hi All,

We all are familiar with coloring events in Outlook calendar. Question is can we have the same deal with SharePoint calendar and the answer is yes we can have. In this article, I am going to share few tips on how to achieve this functionality.

To achieve this, first create one field in Calendar list. For example, give it a name “Category”. Your each event is divided in some category. Give it as choice column and enter following categories for selection choice.



So, your each event is divided in these two categories. So now, go ahead and add two entries in calendar. One of Sports and other is of important meeting category.



Also create one more calculated column called “CatTitle”



And change the calendar view to this



And now we will add one content editor web part below calendar web part. So Edit the page and add one content editor web part and add the following line of code. This will color the different events.

<script>

var SEPARATOR = "|||";

var nodes, category;

nodes = document.getElementsByTagName("a");


for(var i = 0; i < nodes.length; i++)
{

if(nodes[i].innerText.indexOf(SEPARATOR) != -1)
{



UpdateCalendarEntryText(nodes[i]);


var foundNode = nodes[i];
var trap = 0;

while(foundNode.nodeName.toLowerCase() != "td")
{
foundNode = foundNode.parentNode;

trap++;
if(trap > 10)
{
break; // don't want to end up in a loop

}
}

var colour = GetCalendarColour(category);



if(colour != "")

foundNode.style.background = colour;
}
}

function UpdateCalendarEntryText(anchorNode)
{

var children = anchorNode.childNodes;
for(var i = 0; i < children.length; i++)
{

if(children[i].nodeType == 3 && children[i].nodeValue.indexOf(SEPARATOR) != -1)
{
var parts = children[i].nodeValue.split(SEPARATOR);

category = parts[0];
children[i].nodeValue = parts[1];
}

else
UpdateCalendarEntryText(children[i]);
}
}

function GetCalendarColour(desc)
{

var colour;

switch(desc.toLowerCase())
{

case "sports event":
colour = "#3399FF";
break;

case "important meeting":
colour = "#FF33FF";
break;


default:
colour = "";
}

return colour;

}

</script>




I would like to thank Mark Wilson for this wonderful trick.

That's it. your job is done.

Thursday, October 15, 2009

Hiding field in SharePoint through JavaScript

Hi All,

Many times we require to hide specific field in new form, disp form and edit form. This time we will do it with the help of javascript. We can do the same thing with the help of SharePoint API. However we will cover here that how to achieve the same with the help of JavaScript.

Let us go to calendar and click on new. You will now be on Newform.aspx. We can see here one field named “WorkSpace”. If we don’t want user to create any workspace here, then we can hide this field with the help of JavaScript code.



To hide a specific field, insert one content editor web part on the page and then just copy and paste the following code. Insert this web part below the new form web part.

<script type="text/javascript">
function HideField(title){
var header_h3=document.getElementsByTagName("h3") ;

for(var i = 0; i <header_h3.length; i++)
{
var el = header_h3[i];
var foundField ;
if(el.className=="ms-standardheader")
{
for(var j=0; j<el.childNodes.length; j++)
{
if(el.childNodes[j].innerHTML == title || el.childNodes[j].nodeValue == title)
{
var elRow = el.parentNode.parentNode ;
elRow.style.display = "none"; //and hide the row
foundField = true ;
break;
}
}
}
if(foundField)
break ;
}
}

HideField("Workspace");

</script>


After you’ve inserted this code, just look at the result shown below.



That’s it. Your job is done. You can apply the same code in disp and edit form as well.

Monday, October 12, 2009

Sharepoint’s “!New” indicator duration.

Hi folks,

Here we are explaining a way, how to change “!New” indicator time span.

Below is the command to change the time of “!New” label of SharePoint Item

stsadm.exe -o setproperty -pn days-to-show-new-icon -pv <> -url [Your Virtual Server's URL]


To turn off the “!New” icon, set the number of days to zero

Here is the MSDN KB link for the same.

The change is for ALL list items (not just documents) on the virtual server
Good thing is it does not required IISRESET

Saturday, October 10, 2009

'' is not recognized as an internal or external command

Hi All,
I face a problem when i create .bat file in Visual studio it add an extran non-ASCII character in my bat file and i am getting error '' is not recognized as an internal or external command,
it is because it is UTF-8 format

so to fix it Use notepad++ and paste your .bat code in it and go to Format Menu select ASCII format and save it it will work like charm :)


Happy SharePointing....


SharePointKings

Tuesday, October 6, 2009

Office SharePoint Search Service hangs does not start

Hi All,
I have faced one strange problem i was restarting Office SharePoint Search Service on my farm environment and suddenly it got hanged it is showing me in starting state there is no stop,start or restart option in services.msc console. I have restarted my machine but still error was as it is.
I tried following command also

stsadm -o osearch -action start
stsadm -o osearch -action stop
net stop oSearch
net start oSearch
nothing was working for me it shows me operation time out as osearch service is in starting state.

I fixed it by
psconfig -cmd services -install
and configure SharePoint search again and it works for me.

warning: follow above instruction at your risk on production environment :)

SharePointKings

Sunday, October 4, 2009

MOSS 2007 Master Page DOCTYPE Issue

Hi All,
Today i would like to discuss an issue which i think most of us would have faced when we try to add a declaration in the top of the master page like:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


This is a standard declaration you will see on any aspx page and we all know why it is required.

But when you add this declaration in a SharePoint master page...you are inviting trouble..why..simply because of the reason that SharePoint master page is XHTML non-compliant.
You will ask me why you need a DOCTYPE in a master page?
Reason being the fact that i am using a AJAX modal pop up in the master page and we all know what happens when you add a ajax control in a master page without a doctype declaration..The page looks weird and the structure breaks from many places.

The only solution i know in this case is to choose from one of the following options:

1. Remove the AJAX modal pop up and hence the DOCTYPE declaration and use some other pop up . A javascript pop up may be
2. Keep the DOCTYPE declaration and modify the style of the elements whose structure is broken as an effect of adding doctype.

Hmm...you can't refuse clients requirement , and hence you have to go with option 2.

Consider for example after adding DOCTYPE the quick launch menu started looking weird, You tried changing the style sheet class attributes but no use.
The reason being the fact that the master page is no longer taking the out of the box style sheet classes like ms-navheader !
Follow the steps mentioned below and get rid of this problem:
1. Create a new class in your style sheet (Note: Do not make change in CORE.css)
and copy the attributes you were using previously in it e.g if the previous class name was ms-navheader then create a new class by name such as leftnavheader and copy the attributes under its declaration. Similarly create other classes.
2. Open the master page in the designer and replace the old class name with new one at all the places.
3. Save and publish the master page and you will see the changes are visible now.

Go ahead and follow the same procedure at all the places. I know its strange but can't help it.

If you have some better way of solving this issue or facing any problem understanding this post please let us know at sharepointkings@gmail.com

Happy Coding !!



Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com