Sunday, 28 February 2010

SharePoint 2010 LoadQuery Vs Load Methods

In SharePoint 2010 we can speak about a year continuously about the new features and APIs. They have included plenty of things and should be made developer life easy!!!
Here is a nice concept I want to tell to my readers about what is the difference between the load() and loadQuery() methods. The main definition both will use to load the data or objects you want from the SharePoint server. Then where is the difference?

To reduce the confusion, first, we will discuss these in the Managed Client OM [C#].
1. Difference in syntax:
Managed Client object model supports two types of syntax in data retrieval process. One is Query syntax [Linq] and another is Method Syntax.

In Query syntax we are using Linq to create queries. Remember, here we are doing Linq to Objects querying but not Linq to SharePoint Provider. It means all the stuff we are writing is client side coding, we can't make or write queries to Linq to SharePoint provider. So, everything should be Linq to Objects only. LoadQuery() syntax can only be used with the query syntax. I mean if you want to write Linq query and execute against client object model, then we should use LoadQuery(). In other words, LoadQuery method takes an object of type IQueryable as its parameter, and this allows us to write LINQ queries instead of CAML to filter the results. Take the below example.
var query = from list 
in clientContext.Web.Lists
where list.Hidden != false
select list;

var result = clientContext.LoadQuery(query);
clientContext.ExecuteQuery();
In the above example, I have used the Linq query to find all the lists which are not hidden. So, this is a straight Linq query and we should use the LoadQuery() method to execute it and get result.

Method syntax can be used with either Load() or LoadQuery(). We can use Lambda expressions to query the data. We can use the same above example with lambda expressions as below.
clientContext.Load(clientContext.Web, 
website => website.Lists.Include(
list => list.Title).Where(
list => list.Hidden != false));

clientContext.ExecuteQuery();
It also produces the same result as above. But the only difference is syntax.
In the above example, we have used the Include phrase. What's is this? It's main advantage is for the performance and efficiency.

How it is improving performance? Because we are returning only the properties we need, not all from the server belongs to requested object. So, Include phrase will tell the server to return only the properties defined in me. In our example, it only asks for Title, so server returns only Title property and loads into the response. This will increase the performance for sure.

How to use Include in LoadQuery() syntax?
IEnumerable hiddenLists = clientContext.LoadQuery(
listCollection.Include(list => list.Title).Where(list => !list.Hidden));

2. Difference in implementation:
Load method populates the client object directly with what it gets data from the server. But LoadQuery returns the data as a completely new collection. For better understanding, LoadQuery() returns the data in the format of IEnumerable<object>. It means all the collection is of type IEnumerable but not straight object collection. For example, in the above example, we have tried to retrieve all lists from the server which are not hidden. If we use Load() method, it returns the ListCollection type. If we use LoadQuery() it returns the IEnumberable type instead of ListCollection. Because of this, when you use Load() method the data will be garbage collected if and only if the ClientContext object goes out of scope. Whereas LoadQuery() object will be garbage collected if the enumerable object goes out of scope irrespective of the ClientContext object.

Using ECMAScript LoadQuery() Vs Load()
What we have discussed about them in the Managed Client Object Model are same here except the server side concepts like garbage collection etc... We will discuss now on how we can implement them in the ECMAScript.
load():
var web = clientContext.get_web();
var lists = web.get_lists();
clientContext.Load(lists, 'Title');
loadQuery():
var collList = clientContext.get_web().get_lists();
this.lists = clientContext.loadQuery(collList, 'Include(Title)');
For filtering data, we need to write the CAML Queries and pull information from server.

Hope this whole concept is completely about the difference between and loadquery and load. And I believe you better understand it. Please let me know the feedback and questions if you have any.

Friday, 26 February 2010

SharePoint 2010 HTML Markup changes in rendering

Wow. SharePoint 2010 has lot of new features. Everyone knows that. But, among all of them, the main thing I have really loved is the HTML markup generated for the SharePoint 2010. You know what? They have replaced the tables with Div and ul, li etc. So, this is a very good thinking and change from SharePoint team which likes by all and browsers. Everyone knows what are the problems with TABLES and in SharePoint 2007 you find many many tables. But not any more in SharePoint 2010.
Below is the simple snapshot which is taken from the view source of SharePoint 2010 Publishing site template.

What if you are trying to migrate from SharePoint 2007 to SharePoint 2010? 2007 version is built on TABLES and 2010 version is built on DIVS. Don't confuse here. All the SharePoint built-in controls like SharePoint navigation, Quick launch etc renders as TABLES in SharePoint 2007 and in SharePoint 2010 they render as Divs.  So, the format is changed. If you have done plenty of customization in 2007 web site and tried to migrate 2010 site, then I am not sure you will be succeeded in formatting after migration. So, by considering this issue into account Microsoft SharePoint team introduced a nice concept called "visual Upgrade". So, what this means? Once you are done with the migration, do you want to change the UI [visual upgrade] from v3 to v4 or not . V3 uses the version 3 rendering the TABLES formatting, whereas V4 uses the Version 4 renders in the format of DIVS. For better understanding the concept, I will show you above terms in terms of figures.

Visual Upgrade
Once we are done with SharePoint site migration[to SharePoint 2010], you will see the same layout and UI as previous site [SharePoint 2007]. The UI is not really migrated to the SharePoint 2010 UI [V4]. So, what to do to migrate UI too to SharePoint 2010 format?
Now, you can see a new item in the site actions menu named "Visual Upgrade" as shown below.
When you click on the Visual Upgrade option, then you go to a page where you can see three options to preview how it looks like in v4. See below image.
  1. Here, the option 1 means, display the same UI as the v3 UI. i.e. Your SharePoint 2007 UI.
  2. Option 2 is, Preview the site in V4 mode, but, don't save it permanently. So that you have chance to take a look at the site in V4 mode and if you think UI is not well formatted then revert the changes back to V3.
  3. Option 3 is, Permanently change the UI to V4 mode. If you select this, then you can't change the UI back to V3 mode and the option "Visual Upgrade" under site actions will go away.
 I think, you understood it well and will greatly use the advantage of this feature. Love to hear something from you.

SharePoint 2010 ECMAScript - How to know logged in user information

This is post which is simple and not really needed. But when I started writing the code in ECMAScript I have faced problems in getting the logged in user information. So, my readers may feel good after see this post and really most the users are looking for this too.
By this time, we have really understood all about ECMAScript Client Object Model and debugging. So, it's easy for us to know it well.
Please find the code below to get the current user information.
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getWebUserData, "sp.js");
var context = null;
var web = null;
var currentUser = null;
function getWebUserData() {
context = new SP.ClientContext.get_current();
web = context.get_web();
currentUser = web.get_currentUser();
currentUser.retrieve();
context.load(web);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args) {
var userObject = web.get_currentUser();
alert('User name:' + userObject.get_title() + '\n Login Name:' + userObject.get_loginName());
}
function onFailureMethod(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
So, the above code returns you the user object and displays user name and user login name. You can customize it as you want and please let me know the feedback or questions you have.

SharePoint 2010 ECMAScript - how to know all methods in SP object and debug

After spent good time to write nice posts on Client Object Model and ECMAScript how to use, I want to present you another nice tip on how we know all the methods and properties available for the SP object in the ECMA javascript . MSDN documentation is not finalized or completed yet to know what properties and methods  for SP objects have. And when you want to query something [like list or web] and you are not aware of what it has inside methods and properties, then the best way as far as I know is, using the Javascript debugging using Internet Explorer.

If you take the same example which from the post "How to get the web site properties", I have declared the web object and reading that when it fills. How I knew that for the web object there are methods named get_title() and get_id()? Follow the below steps to reveal that.
  1. After you are ready with the script added to the page, Follow the steps...
  2. Open the page in Internet Explorer and Select Developer Tools from Tools Menu as shown in below figure. Needs >= IE 7 version installed.
  3. Find the script tab from the developer tools.
  4. Select the file from the list of files where the custom javascript you have written.
  5. Now go to the location of javascript code, and place the break point to debug.
  6. Now, on the top, click on the button start debugging. This will start loading the breakpoints in the files. When the code reaches where the breakpoint is present debug starts and you can find them.
  7. Now, go to the ASPX page and refresh it. From the page execute the code. [If you have written code to execute on page load then fine we don't do anything, it will automatically reaches breakpoint and if you have written the code to execute when some event raises then do raise that event(just like button click or something else).]
  8. When you do that, then the debugger will find the breakpoint and starts debugging as shown below.
  9. Press F10 to repeat through the code one line at a time. Stop at the place where you want to debug and find the methods of an object or see the values and select that part and right click, select "Add Watch". For example, In my case I am trying to find the web properties and adding watch the web object as shown in the below figure.
  10. Now see all the existing methods available for the object. This is the best and efficient way to know the methods in an object and another advantage is you can directly see what value it will return by using a specific method by adding that to watch. But take care, you can see only the data which is actually coming from the server. You have selected Title and Id from the example we are using, If you use the method web.get_description() then it will give you error. So, make sure you have loaded the property before you access it.
This is what all about knowing the properties and debug the data and see the information. It has helped me so many times and in fact I rely on this to know the methods in any SP object. The will surely help to all SharePoint 2010 devs who are working on the ECMAScript client object model. Hope you like this post and it helps you for better programming.

Thursday, 25 February 2010

SharePoint 2010 - Client Object Model - ECMAScript - Introduction on how to use

In SharePoint 2010, the great feature is introducing the client object model [Read this article before proceed]. The great advantage with this is, we can do plenty of things without server side coding using the ECMAScript. There are plenty of default supported files to use and do whatever you want with the SP Package files. All javascript files will be found in the layouts folder. All of them starts with "SP" name.

ECMAScript works only for the current context. It means from outside of the site, you can't access the SharePoint data. This won't support the cross-site scripting.

How to add the reference to SP.js and access the data?

  1. Refer it from the client side: Create a js file somewhere in the SharePoint site which can be accessible and write the below line as the first line.


    ExecuteOrDelayUntilScriptLoaded(initialize, "sp.js");
  2. Refer it from the server side: Add the below line to the ASPX page.


Note: It's not really needed to use refer from server side code added to page to execute the code.

What this method is doing?
In javascript when you request files, all will load asynchronously. I mean, they will load randomly and what if your javascript is using sp.js file and it's not loaded yet? This will be a problem. So, this method helps to tell the browser to wait and execute the "initialize" function if and only if sp.js file is loaded.

Note: If you are using the separate js file then paste the below code by removing the script tags. If you are using the script on ASPX page or in Content editor web part then copy all the code and paste.

A small example:
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getWebSiteData, "sp.js");
var context = null;
var web = null;
function getWebSiteData() {
context = new SP.ClientContext.get_current();
web = context.get_web();
context.load(web);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args) {
alert('web title:' + web.get_title() + '\n ID:' + web.get_id());
}
function onFaiureMethodl(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
Explanation:
I think you understood well by seeing the above without any difficulties. Simply I will explain the steps.
  1. I am getting the current context by calling the get_current() method.
  2. Get the current web site [Where we have write the javascript code, will get that web object.]
  3. context.load() - I know it's not straight forward to understand. But, it's simple. When you send the request to server, what we need to get back from the server as response? That is what we need to place in the load method. In this case, load is invoked with web parameter. It means it will load the complete web object with all properties.
  4. When you write load, it means it won't load the object immediately. We need explicitly call it by using executeQueryAsync() method. As the name says, this method is asynchronous call. And the syntax shows that it is a callback call. It has the success method and the failure method. So, when the query is succeeded then it goes to the success method, otherwise it goes to the failure method.
Load only the data you want, not the whole web object:
This is a performance and efficient related thing. Everyone knows in SQL, why we don't use select * always, and use only select and then only columns you needed to process something in the selected list? The same reason here too. Don't query all the properties in an object and only query the properties you actually needed. This is looking fine, but how to do that? In  my above example, I am actually using only Title and Id, I want to load only them. For that I need to use the below line.
context.load(web, 'Title','Id');  
If you added comma separated properties then it will query those properties and load data. There is another option also available named loadQuery(). I will tell you about this in later posts.

NOTE: Remember, all the properties are case-sensitive. I have wasted 1 hour to find out a small problem. I have used the 'ID' instead of 'Id' in properties and running into trouble. So, make sure you are aware of that.

You can debug and there is a file which helps you to debug upto inner imeplementations. The file is sp.debug.js and you can find it in layouts folder. This is good practice to use it on dev environment, but don't forget to remove this reference on the production environment.

Wednesday, 24 February 2010

SharePoint 2010 - Complete details about Client Object Model

This is the introduction to the Client Object model introduced in the SharePoint 2010. This is going to be a huge help and useful part in SharePoint 2010 for developers and makes lot of customization to the existing SharePoint system.

In eariler versions, I mean till SharePoint 2007 the code runs using the SharePoint object model to run against the server which is running SharePoint. Other than the SharePoint server object model, other way is, simply reference the web service and use that to get and manipulate data. Then what is the need of SharePoint 2010 Client object model[Cleint OM] concept?

What is Client Object Model?
Client Object Model is introduced in SharePoint 2010 which helps to developers to make things easier to develop the client side applications for SharePoint 2010. Client Object Model can run on the client machines (Where SharePoint is not installed) and communicate with the SharePoint server remotely. This is the great advantage for the SharePoint devs as they don't have to install SharePoint for development any more.

What are the different Client OM supporting in the SharePoint 2010 API? [Client API]
  1. .NET Managed Client - Implemented in .NET CLR. I mean we use this in Web, Windows and Console applications.
  2. Silverlight Client - You can use the SharePoint objects in Silver light coding. Wow, this is going to be a huge advantage to  the Silverlight applications which can be integrated into SharePoint. Before we don't have access to SharePoint objects inside Silverlight context.
  3. ECMAScript Client - Through javascript too, we can get context and do manipulations to SharePoint objects. Do you think it's possible? Yes, its a brilliant way of thinking from Microsoft SharePoint team and this will help in great scenarios. Will explain later in this article.
Why Client Object Model comes into the picture? Are there any specialties of them?
The main started point to think by SharePoint team are as follows.
  1. Is it really necessary to have SharePoint installed on server for SharePoint development? - Yes, in SharePoint 2007 you have to install SharePoint on the server to write code and test it.
  2. What is the advantage of writing more web services to serve what the clients are looking for? - This is completely not a feasible solution to give or expose web services for each and every single requirement to get and manipulate data. It has plenty of limitations and if Microsoft exposes 500 web services and you didn't find what you really need and they are just waste. Instead write whatever you want and use them.
  3. The great thinking and beautiful solution to the people who don't allow server side coding in the SharePoint sites is ECMAscript client OM. You can create a simple javascript file and deploy into the server to get what you needed. As we know, most of the clients don't allow server side coding but they want something to be developed. In SharePoint 2007 it's very difficult to get this job done. But now in SP 2010 very easy.
So, these things take into high priority and makes them to come up with a great solution in the form of Client Object Model. The great advantage of it is completely looks [Syntax] like the SharePoint Object Model. So, nothing new for developers and no confusion. Infact very simple to manage and write code.

SharePoint object model syntax:
Server side syntaxClient side syntax
SPContextClientContext
SPSiteSite
SPWebWeb
SPListList
Now, I believe you have understood the Client OM concept. Now, we will discuss a little bit about technical implementation.
SharePoint 2010 provides the client support files to refer the SharePoint objects and communicate with the SharePoint server. Below are the details.
For Managed ClientDLL's needed : Microsoft.SharePoint.Client.dll, Microsoft.SharePoint.Client.Runtime.dll. Find these files in the 14/ISAPI folder. Usually, the location would be at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI".
SilverlightMicrosoft.SharePoint.Client.Silverlight.dll and Microsoft.SharePoint.Client.Silverlight.Runtime.dll. They find at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin".
ECMAScriptSP.js file - The file fund at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS".

What we need to do is, add the relted file to the project references if it is Managed client or Silverlight and start using the SharePoint objects in the code. If it is ECMAScript then we just need to declare the line     ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js"); on the top of js file to use the SP object.
**Initialize is some javascript function.**
My next posts will be the examples of each client OM implementation and how to get, manipulate data for better understanding.

Retrieving the COM class factory for component with CLSID {BDEADF26-C265-11D0-BCED-00A0C90AB50F} failed due to the following error: 800703fa

This is a SharePoint 2010 BETA edition exception. Most of the people who are working with SP2010 should get this exception. Below are the exception details:

Retrieving the COM class factory for component with CLSID {BDEADF26-C265-11D0-BCED-00A0C90AB50F} failed due to the following error: 800703fa.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {BDEADF26-C265-11D0-BCED-00A0C90AB50F} failed due to the following error: 800703fa.

Workaround:
  1. Doing an IISRESET solving the problem but it is solving temporarily.
  2. Open IIS and go to your SharePoint site. And find the application pool.
  3. Go to application pool, click Advanced settings, change the value for "Load User Profile" to "true".
That's it!!! You are done.
Special thanks to Bassem Georgi for the nice tip.

Monday, 22 February 2010

JQuery 1.4.2 released

These guys are very quick and fast updates in releases. Jquery 1.4.2 is released and they came up with strong version. This version again improved plenty of things in terms of performance and some events. Fixed lot of issues and bugs. So, get it and use it. Read the complete list of features on their site.

http://blog.jquery.com/2010/02/19/jquery-142-released/

Tuesday, 16 February 2010

SharePoint 2010 site templates not showing in create site page, How to get them?

This is a bit surprising to the people who are playing with SharePoint 2010 very first time. When we try to create subsites in the main site collection we need to pick the right site template and go. But, what if you are not able to see the list of site templates in the list?
  1. I have created a simple publishing site in SharePoint 2010 server and below is the screen which looks like by default.
     

  2. And I like to create a blog site inside it. And I go to Site Actions and selected Create a site and below is the screen I saw.
  3. [The cool thing in the above screen is, it is implemented in Silverlight. And it loads very fast with nice effects.] But,  here I am not able to see all site templates available in the system. By default it is showing only two. So, How to create a blog site now? How to get all the site templates back?
  4. It just simple and follow this. Go to Site settings and move to the section "look and feel" as shown in below screen.
  5. If you see, there is a link named "Page layouts and site templates". That is what we needed. Just click on that link.
  6. Now, below is the screen you see, which has the complete list of site templates and page layouts available in the system.
     
  7. If you see the above screen, there are only two templates selected by default. This is the reason why we see only two templates available on the create site page. So, add how many templates you want from the left side. You can do the same with page layouts too. Select all page layouts you needed and save it.
Hope this helps.

User profile import problems in SharePoint 2010

I know, most of the SharePoint administrators and development team facing problems with importing or syncing up the active directory with user profile store or SSP in SharePoint 2010. There are many reasons and you need to read the complete documentation before do anything.

I have initiated the thread in MSDN forums here and still that is growing. User profile import

But, there are some configurations we need to check before do the user profile import. One of the important notes is "The farm is running either the Standard or Enterprise version of SharePoint Server 2010 and you have run the farm configuration wizard. Profile Synchronization does not work on a stand-alone installation for SharePoint Server 2010 Beta."

**UPDATED** 2/24/2010
After spent 16 hours of research [late nights] found some nice scenarios on it. Below are all of them.
All this research result will only helps to the people who just started the installation of the SharePoint 2010, and it won't help much to the people who already tried to add a new connection. You should be need to rebuild of SharePoint 2010 in that case to get it working.
  1. Please make sure you have installed the WCF hot fix before proceed.
  2. After you have installed successfully the SharePoint 2010 and completed the SharePoint configuration Wizard, don't try to do something with User profile service. If you do then the only solution is rebuild whole farm again.
  3. Assuming AD is ready and you should have delegate control [Replicating directory changes] to the service account you are using.
  4. Go to System Settings from central administration and click on the link Manage services on the server.
  5. Start User Profile Synchronization Service. By default it is stop, we need to start it manually.
  6. Now, you see the status changed to Starting.
  7.  Now, the profile job is running [you can check the running jobs by going to Monitoring section and find the job ProfileSynchronizationSetupJob is running.]. This job will take minutes to complete. 
  8. If service is showing starting for a long time, then something went wrong and you need to rebuild the farm.
  9. If you see the status Started then you are the luckiest person and the service started.
  10. Now, it's the time to go the application management and user profile service application to create a new configuration synchronization connection.
  11. Here, fill the form and select only the Users or the OU you want[not all] and hit OK.
  12. If you see any new connection in the list then you are safe. Otherwise you are gone, only way is rebuild the farm....

So, this whole process took me 16 hours to test. So, take care with this buggy thing in SharePoint 2010 BETA.
** End of update ** Special thanks to Jie Li

So, you should be running the standard or enterprise version of SharePoint 2010. You can read the complete details of it for finding more here.
http://technet.microsoft.com/en-us/library/ee721049%28office.14%29.aspx

please let me know, if you have any problems in accessing or configuration.

JQuery conflict when using different javascript libraries

Today, I came to a scenario where I need to use JQuery and Prototype libraries in my application. Both are operating with $() to access the objects and do the client side logic. But, the $() is getting conflicted between JQuery and Prototype libraries and things got messed up. So, it should be a good practice to distinguish them because who knows what requirements come in future and how many client side javascript technologies we are going to use. The code which we have shouldn't effect anything, right?.

The same thing happen in my SharePoint sites too. When I tried to migrate from SharePoint 2007 to SharePoint 2010, the client side script [JQuery] custom developed is not working. The only reason behind is the conflicts in the javascript. The file SP.js in the SharePoint 2010 causing the problem.

So, make sure, if you have used JQuery in your applications, always the best practice is declare the Jquery global instance variable and then start using that instead of directly use the $(). For example,
var $j = jQuery.noConflict();

// Use jQuery via $j(...)
$j(document).ready(function(){
$j(".someclass").hide();
});

So, in the above code, we actually referring the $j() instead of directly $(), so it won't give any problems in future. No matter what how many different client side javascript technologies used, that should work. For more information check it here.

Hope you like this post and love to hear comments.

Monday, 15 February 2010

SharePoint Exception: No item exists [url]. It may have been deleted or renamed by another user.

This is one of the exception regularly comes when we do custom development and create custom aspx pages. Everything works fine and no code issues but still this exception comes. I worked hard to fix this problem so long time. Tracked everything like logs, event viewer and more tips. Nothing helps. Then  spent some nice time and trail and error methods found the problem and fixed.

More details about exception:
No item exists at http://mysharepointsite/Pages/Home.aspx?id=4&q=HQ.  It may have been deleted or renamed by another user.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Microsoft.SharePoint.SPException: No item exists at http://mysharepointsite/Pages/Home.aspx?id=4&q=HQ.  It may have been deleted or renamed by another user.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

What's the problem?
The problem is in my custom ASPX page, I am using a querystring with the key "id". Do you believe this? which is causing the problem?

Yes, 100% sure. This is what causing the problem. This problem came in  my two successive SharePoint projects and finally by changing the querystring key from id to someother key named like "sid" or "aid" or something other than "id" worked.

I am not really 100% sure what's happening when I use "id" key in the querystring, but by changing that everything works fine. So, don't use the querystring "id" in your cusotm SharePoint ASPX pages.

Note: There are chances that you may think the page is checked out or removed by some other user, then that's a mistake.

Hope this helps and save you from killing so much time to know the problem.

SharePoint Exception: Coercion Failed: Input cannot be null for this coercion

This is the exception, I am seeing very first time in SharePoint development. What I tried was, through SharePoint designer I tried to update the list item. The source and destination lists are having a field of type choice. I want to grab the choice field information from source list and update the destination list choice field.
The problem occurs only when the source choice field is empty.

More clearly, I have a list with checkbox list field. When a new list item is added, the workflow triggers and start updating the another list item with the current item information. And when I select nothing in the checkbox list field, then it throws the exception "SharePoint Exception: Coercion Failed: Input cannot be null for this coercion".

So, why the problem comes?
Because in update list item phrase in SharePoint designer I have selected the lookup for choice Return field as as Choices, Comma delimited. See the below screenshot.
Once changed that back to the As String then everything worked perfect. But, didn't get the reason behind. When nothing selected, then it shouldn't do any operation. It should check for null and do nothing. May be a built-in problem or something interesting with this.

Hope this helps to understand it well and solve your problem.

Friday, 12 February 2010

Declarative workflows cannot automatically start if the triggering action was performed by System Account

This is the exception came to me today when I try to run a workflow on a list when an item is created. I tried different combination and didn't get the problem resolved. Even I removed all workflow conditions and actions and placed a simple update like update the title of the item in workflow body. Still that didn't give me the result. The workflow  is not starting at all automcatically.

After some research found that, when we are using system account [With the account we installed SharePoint], the workflows won't run automatically. This is looking crazy but that is what the problem. When I try to run them manually, then they are running absolutely fine, but they aren't starting automatically.

When I try to login with another account other than system account, no problems. Workflow starts automatically. The only reason is "if we install SP1 package, then declarative workflows can no longer be triggered by the SharePoint System account" as there is the possibility of security vulnerability. So, they didn't give access to run the declarative workflows under the System account.

So, friends, if you face any type of these problems make sure you login with some other account other than system account. Hope this helps to save at least 2-3 hours of time.

Team Explorer 2008 and TFS 2010

Can we connect to TFS 2010 from Team explorer 2008? This is the question to most of the people who want to use TFS 2010, but, they don't have VS 2010 installed by chance. So, no need to bother. Visual studio 2008, Team explorer 2008 supports it and you can connect to 2010 TFS server. But, you need to install one package for the forward compatibility for VSTS 2008 version. You can download it here.
Visual Studio Team System 2008 Service Pack 1 Forward Compatibility Update for Team Foundation Server 2010 (Installer)

But, before you install it, make sure you have installed the VS SP1 and Team Explorer SP1.
Visual Studio SP1 and Team Explorer SP1

Before you install anything, please read the article to avoid problems.
Installation order of packages

That's it!!!

Monday, 8 February 2010

ASP.NET Checkbox click on label calling click event twice in JQuery

I don't know this is a known issue in Mozilla Firefox browser. When I use ASP.NET checkbox on a web page, it will render as a input control plus label. So, when I click on checkbox or label the click event raises and checkbox  state changes. But, I figured out  a strange behavior. When I click on the label the click event is raising twice when I use JQuery [I didn't try with  javascript]. But, where as when I click on checkbox it is raising click event only once. How to solve this problem? I have tried so many ways to solve the problem. But, didn't success.
I have tried by using type of the control. If type is checkbox then only go inside or just do nothing. When I click on label, it is coming to click event and every time, all lines are executing. I don't know why this is happening. Wheat I understood is, when we click on label then internally it is again generating click event for the checkbox because of the label for attribute. So, take care of it.
And if you find any solution to this problem, please let me know.

JQuery 1.4.1 released

It's a good news for all JQuery lovers. The latest version of JQuery 1.4.1 has been released and getting very popular. Personally, I feel very good. The secret of success this version is the performance improvement, some changes to existing methods and new additions. This is very nice to know the functions are executing less time than they were.
You can link the JQuery files from Google servers from this location.
http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js
They have made plenty of changes to setter, getter and ajax methods.
The whole API changes are documented here.
http://api.jquery.com/category/version/1.4/

Why to wait, get the latest version and start playing with it.

Sunday, 7 February 2010

JQuery live() method for Focus and Blur

Everyone knows these days we are liking the client side implementation as much as we can. That is the only reason why all the client side languages are more popular. In Jquery, Live() method is very nice concept and as we know it is not supporting all the events. [Hope in version 1.4.* it is coming.] I had a requirement to raise an event when user goes away from the input control and that input controls are dynamically generated. But, as we know, we don't have live() method support for blur and focus events, we need to simulate or write our own. Below is the best way to implement that.
http://stackoverflow.com/questions/1199293/simulating-focus-and-blur-in-jquery-live-method
This is very easy and simple to understand. The same way, we can implement the other events we needed. Hope this helps and will do much with JQuery.

Thursday, 4 February 2010

SharePoint Querying - CAML Query usage when special characters in DATA

We have many ways of pulling information from SharePoint sites. Depends on the requirements we may use web services or using SharePoint object model. If you have requirement to filter data from a SharePoint list then the best option is through CAML queries we will write a simple query and run it against the SharePoint list and get the collection of data. So, if you are familiar with CAML queries then no need to say how to write and how they will execute. But, this post main focus is on what if the data which you are querying contains the special characters like '&'. The query won't run and it fails. Take the example of below code.
 <Where><Contains><FieldRef Name='Description' /><Value Type='Note'>Praveen&Battula</Value></Contains></Where>
The above query will leads to errors and you see the error in the logs. So, what is the problem? There are no syntax errors and everything is perfect. But, where is the problem? The problem is as we discussed the symbol '&' in the data [Praveen&Battula]. So, how to solve this problem? Below is the simple solution.
<Where><Contains><FieldRef Name='Description' /><Value Type='Note'><![CDATA[Praveen&Battula]]></Value></Contains></Where>

I think, by seeing above syntax, you may get the answer. :). What I did is, we are familar with XML and we know how to handle special characters in XML[Using <![CDATA[Some DATA]]>]. So, I used the same logic here and everything started working as expected.

**UPDATED**
From the comments, I found a special scenario of why it fails even we use CDATA. Check it below.
http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/8b442d22-eb56-40d8-a487-a325d3a70626/
I am trying to solve this, but for now, the only solution is through encode it and query it.

Please let me know, your ideas on it.

Monday, 1 February 2010

SSRS Reports get Month name from Month Index or from date

This is one of the small tips which I want to tell my readers. When you work with SSRS reports, you may come across with the requirement like, you know the index of the month, but you want to print month name from it. So, if that is the situation for you, this is the right post for you. :)
MonthName(monthindex) 
You may get it from t-SQL as I mentioned in my previous post here.
But in SSRS reports the way you  need to approach is like this.
  1. Take a textbox to report body.
  2. Write the below syntax into it [As you know, it is the expression].
=MonthName(7)

In any case, you need to get it by date then you still use this below function.
=MonthName(Month(Fields!datefield.Value))

Hope this helps and please let me know, if you face any problems.