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



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