Tuesday, September 28, 2010

SharePoint Cascading drop downs using jQuery

Hi All,

How many times you require functionality where in based on the selection of parent drop down generates the values to the child drop down. Examples, selection of country fills the states drop down.

Well, of course there is a way like creating custom field which can definitely achieve this job. However this requires us to write down the code and .ascx custom fields and deploy on the server to get it to the action.

We can achieve the same with the help of jQuery. Yes, no files and no code. Without them we can achieve this. So why to wait? Let’s explore more in this.

Before we start the exam, you will need to fantastic jQuery from

jQuery 1.3.2.min.js

and SPServices jQuery from

SPServices jQuery

Once you download these two .js files, upload them to any of the document library where you have the permission over the site.

Now go ahead and create one list. I am calling it a CategoryType and adding two values in the list.



Now I am creating one more list and call it as a CategoryRelationList and create one column called Category which is a look up column to the CategoryType title column and add few items.



And now to put it in action, we will create one more list and we call it RequestForm and create two columns, Category look up to CategoryType list title column and Product look up column to the CategoryRelationList title column. This is the list where we will use the cascading drop down service from SPServices jquery library




Now here comes a good part. Now you have two ways to achieve this, the simplest which I believe is by using Content editor web part on both new form and edit form. Add content editor web part and add following lines to it. (Check your document library path in src attribute where you have kept two js files which we downloaded earlier)

<script language="javascript" type="text/javascript" src=" /Shared%20Documents/jquery-1.3.2.min.js"></script>

<script language="javascript" type="text/javascript" src=" /Shared%20Documents/jquery.SPServices-0.5.6.min.js"></script>
<script language="javascript" type="text/javascript">

$(document).ready(function() {
$().SPServices.SPCascadeDropdowns({
relationshipList: "CategoryRelationList",
relationshipListParentColumn: "Category",
relationshipListChildColumn: "Title",
parentColumn: "Category",
childColumn: "Product",
debug: true
});

});
</script>


OR the other way to achieve this is open SharePoint designer and then open site where this list is located, open NewForm.aspx, check out the form and find the following line.

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

Add the above script exactly below this. Save it and check in. This will also do the job for you. Do the same for edit form as well.

Now let me explain each parameter in the script.

relationshipList – This is the name of the list where we have kept the relationship.
relationshipListParentColumn – This is the parent column in the relationship list.
relationshipListChildColumn – This is the child column in the relationship list.
parentColumn – parent column in the list where we want to implement this.
childColumn – child column in the list where we want to implement this.

Now see it in action. Open the list and click on new and see the magic.





Hope that you have enjoyed this post. Keep giving the comments. we love them. :)

Monday, September 20, 2010

Integrating twitter with SharePoint

Hi All,

Interesting integration with SharePoint has come. And yes, you have heard it right. It is the integration of twitter with SharePoint. We have done this for MOSS 2007. If this can be done with 2007 version of SharePoint, it certainly can be done in SPS 2010.

Before starting this topic, first we need to understand the structure of twitter XML file that we will be using in this post. We all know the so popular and ever increasing twitter site. So many people updates some or the other thing on twitter. In twitter they are called statuses.

If you already have an account in twitter or do not have, this XML file has no concern with this, because we can anyways see tweets of anybody even though you do not have account. This XML file read the latest tweet, followers, following and updates. Also shows your user name, photo, location, description and website. Well, actually you need to observe the XML file properly and from there you can get an idea about what all parameters you can retrieve.

For example, if I talk about my profile, malayvasavada, then I need to look for this XML file.

http://twitter.com/users/show/malayvasavada.xml

http://twitter.com/users/show/{twitter user name}.xml

Open this XML in Internet explorer. (In Google chrome, it cannot display properly) And you can see similar to this.

So I get following XML file.


<?xml version="1.0" encoding="UTF-8" ?>
<user>
<id>100438644</id>
<name>Malay Vasavada</name>
<screen_name>malayvasavada</screen_name>
<location>Pune</location>
<description />
<profile_image_url>http://a1.twimg.com/profile_images/600111137/Copy_of_Malay1_normal.JPG</profile_image_url>
<url />
<protected>false</protected>
<followers_count>2</followers_count>
<profile_background_color>EBEBEB</profile_background_color>
<profile_text_color>333333</profile_text_color>
<profile_link_color>990000</profile_link_color>
<profile_sidebar_fill_color>F3F3F3</profile_sidebar_fill_color>
<profile_sidebar_border_color>DFDFDF</profile_sidebar_border_color>
<friends_count>10</friends_count>
<created_at>Wed Dec 30 07:43:33 +0000 2009</created_at>
<favourites_count>0</favourites_count>
<utc_offset>19800</utc_offset>
<time_zone>New Delhi</time_zone>
<profile_background_image_url>http://s.twimg.com/a/1284676327/images/themes/theme7/bg.gif</profile_background_image_url>
<profile_background_tile>false</profile_background_tile>
<profile_use_background_image>true</profile_use_background_image>
<notifications />
<geo_enabled>false</geo_enabled>
<verified>false</verified>
<following />
<statuses_count>24</statuses_count>
<lang>en</lang>
<contributors_enabled>false</contributors_enabled>
<follow_request_sent />
<listed_count>1</listed_count>
<show_all_inline_media>false</show_all_inline_media>
<status>
<created_at>Sat Sep 18 04:01:32 +0000 2010</created_at>
<id>24819814760</id>
<text>Silverlight 5? Hummm....something very good is coming to web. Keep watching.</text>
<source>web</source>
<truncated>false</truncated>
<in_reply_to_status_id />
<in_reply_to_user_id />
<favorited>false</favorited>
<in_reply_to_screen_name />
<retweet_count />
<retweeted>false</retweeted>
<geo />
<coordinates />
<place />
<contributors />
</status>
</user>



As you can see, from the XML, you can get so much information. Name, location, photo URL, even the background color of my twitter profile site, latest tweet, date and time of tweet. So now the point is how to use this XML file and how to present it in SharePoint.

Okay, let us go ahead and use XML web part that SharePoint provides. Create one web part page in any site under any document library. Click on add web part and then add XML web part. Now in the XML Web part, modify shared we part properties. In the XML link, provide the twitter XML file path. Click on Apply and Ok.

Now see what you have got.



You can see profile, latest tweet and followers and so on so forth. However, it is not formatted. It looks ugly. So we need to format this output. When we have XML file with us, the formatting options comes with XSLT files.

You can use Visual Studio to create XSLT file because Visual Studio gives you a fantastic UI to create and suggestions for the attribute and tags.

I have already created one XSLT file here. See below code. You can format according to your need. Just make sure that XML tag remains the same. You can change the layout in term of tables, td and tr, width and height.

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes" />
<xsl:template match="/user">
<style type="text/css">
.dsc{ font-weight:bold; vertical-align:top; text-align:left; } .prof { background-color:#
<xsl:value-of select="profile_background_color" />
; color:#
<xsl:value-of select="profile_text_color" />
; } .prof a { color:#
<xsl:value-of select="profile_link_color" />
; text-decoration:none; overflow:auto; }
</style>


<table width="100%" style="background-image:url({profile_background_image_url}); text-align:center;">

<tr>
<td colspan="3" align="center">

<img src="http://assets1.twitter.com/images/twitter_logo_s.png" />

</td>

</tr>

<tr>

<td colspan="3" align="center">
<a href="http://twitter.com/{screen_name}" target="_blank">
<xsl:value-of select="screen_name" />
</a>
<img src="{profile_image_url}" />
</td>

</tr>

<tr>

<td align="center" colspan="3">
City: <xsl:value-of select="location" />
</td>

</tr>


<tr>

<td align="center" colspan="3">
Language: <xsl:value-of select="lang" />
</td>

</tr>


<tr>

<td align="center" colspan="3">
Status: <xsl:value-of select="status/text" />
</td>

</tr>


<tr>

<td align="center" colspan="3">
Last Status Created Date: <xsl:value-of select="status/created_at" />
</td>

</tr>

<tr>

<td>
Friends count: <xsl:value-of select="friends_count" />
</td>
<td>
Followers_count: <xsl:value-of select="followers_count" />
</td>
<td>
Statuses_count: <xsl:value-of select="statuses_count" />
</td>

</tr>



</table>


</xsl:template>
</xsl:stylesheet>



Open XSL editor in the web part property. Copy and paste the above XML file. Just make sure that the first line has to be at first column, first row area. Exactly at the top of the window and left corner, otherwise you will get an error. "The XSL specified by the XSL property or XSL Link property is not valid, or the XSL file cannot be accessed. Make…..". You might stretch your head whole day finding what went wrong.

And this is the overall result combining XML and XSLT. You have just integrated twitter with SharePoint. Cool, isn’t it?

Friday, September 17, 2010

Finally the result is out

Hi All,

Finally the result is out.

Thursday, September 2, 2010

SharePoint designer does not update email body and email 'to' list

Hi All,

Well here comes one more limitation of SharePoint Designer 2007. I have created one workflow which sends an email for some action. Now I needed to add one more person into email list. So I went to SharePoint designer workflow, and changed to list by adding person email.

I was comfortable thinking that now mail also will go to new person whom I included. But wait a minute, this does not seems to be true, when somebody created new item, mail went off, however new person whom I included didn’t get that mail.

Okay, this is one problem. What is next? Next is the email body problem. I changed the email body as well to include some more details and some formatting, however even this does not seem to be reflecting in the email.

Hence I went through several articles and finally come to know that once it is applied to the list, then you cannot make such changes for emails. Even though you may feel after clicking final finish button that workflow is updating, but it is not.

So I had to recreate entire workflow just to include one more person and to change email body. I am not sure if this problem still persists in SharePoint Designer 2010. Yet have to experiment on this.



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