Saturday, July 10, 2010

There's a BUG! There's a BUG!! There's a BUG in the Discussion Board

This is something fishy!
Recently I was working with discussion boards in MOSS 2007. All seemed well. I had to create a simple discussion board with approval. "No big deal!", "That's non-IT stuff if you use SharePoint!"....... If this is what you feel you are in for a BIG surprise........ (just like I was :-) )
So I went ahead and created a Discussion Board, went into versioning settings, selected "Require Content Approval" and did a few test runs. Everything seemed to be working fine until I tested with different users.
Problem: User X writes a new post. This post goes for approval to User A. Until User A approves the post this post will not be visible to all the users. So the obvious thing to do is for User A to approve which he does but as soon as User A approves the post, User A's name starts appearing everywhere in the post viz-a-viz in the quoted text section, the picture of the person who started the thread. And poor User X who actally started the post is lost.
Reason: Now, when User A approves the post, he/she becomes the user to last update the post i.e. the modified by column of the post is updated to User A. And it so happens that in the flat or threaded view of a discussion the name of the user who last modified the post is displayed. But in our "content approval" case it sends a very wrong message. If you go back to the subject view to see the entire list of threads you see that the User X is still the creator of the post.
Now what: I had posted a question on MSDN forums, this is the link. I was not too satisfied with the answer. It stated to write an event receiver to update the modified by column of the post back to the created by column..

I wish there was a better way....

Tuesday, June 15, 2010

Copying Multipl User Field from one SharePoint List to another

So once again I landed up in trouble because of the Person or Group field (Multiple Selection). Refer earlier post.

Now, this time what I needed to do is I simply needed to copy a Person or Group field with multiple selection enabled to another such column in another list, through an Event Receiver.
You might think - "Why is he writing an event receiver?? Why can't he just use a simple SPD Workflow??"

But as usual.......... there is a catch!!

I have created a SharePoint site with Forms Based Authentication (FBA). My users no longer come from the Active Directory, they come from an SQL Membership API database.
And.... SPD Workflows run under the OWSTIMER.EXE service not the w3wp.exe service.

(For general information the w3wp service is created by the IIS and is used to handle web requests coming to a web server. The OWSTIMER service is created by the Windows SharePoint Timer Service and is used to execute scheduled jobs of SharePoint.)
So, since the SPD Workflows run under a different service, they cannot read the web.config placed under the IIS Service, therefore, they cannot read the Membership API database settings, therefore, SPD Workflows cannot identify FBA users.

So, I write a little bit of code to perform the task at hand i.e. copying multiple users from one column to another (using event receiver).
But again..... things are not as simple as you think. I write this line of code:

oDestinationList["MultiUser"] = oSourceList["MultiUser"];
here

  • DestinationList is Destination List object
  • SourceList is Source List object, and
  • MultiUser is the name of the field

but this simple line of code doesnt work. It states that the source and destination objects are not of the same type and cannot copy code!!!! Why????? I have no clue!

On googling I found a long procedure for copying multiple user fields: Create a SPFieldUserValueCollection object and append user names in this object etc.etc..... thats too much work...

So, on doing a little bit of research I found that there IS a simpler way of achieving this. Here's the code:

oDestinationList["MultiUser"] = Convert.ToString(oSourceList["MultiUser"]);

and it worked!!!! Hurray!!!!

Really SharePoint is funny!! :)

Huzefa Mala.

Monday, June 14, 2010

Send E-Mails to SharePoint Multiple User Field SPD Workflow

I faced a recent problem whilst designing declarative workflows in SPD 2007:
It sounds pretty simple - I needed to send mails using the Workflow to users who were stored in a Person or Group field.
You might think - "What's the big deal in that??".... But here's the catch. The Person or Group field I am referring to allowed multiple user selection.
==Bam==
All hell broke loose. How was this possible??? The Person or Group field just doesn't show up in the Workflow lookup! What do I do? Will I need to write an event receiver? Ohh!!! I didn't want to write code here? It seemed so simple. But wait..... lets try to fool SharePoint.
OK so first I do not allow multiple user selection in my Person or Group field. (You might think what about the already existing records? Data loss! Ya I know.... you might have to do this the hard way - Create a template for your list including content, recreate your list using the template you just created and after finishing all the steps mentioned here add all the entries again..... I told you this was the hard way!)
OK continuing with fooling sharepoint...... now, on preventing multiple user entries my Person or Group field starts appearing in the Workflow lookup for sending mails.
I complete my workflow steps, go back to my list and again allow multiple user selection in my Person or Grop field.
Now lets check whether the workflow is giving any errors.....
No......... no errors! Congratulations! SharePoint has been fooled! (Now can re enter your entries as I had mentioned above)
Happy SharePointing! :)

Monday, May 24, 2010

Mohandas Karamchand Gandhi aka Mahatma Gandhi

I am an Indian and although I have read about my Father of the Nation - Mohandas Karamchand Gandhi aka Mahatma Gandhi before, I recently happened to read his biography.
I was thoroughly amazed! I couldn't believe that how could I have missed these points about the Mahatma's life earlier. But what I read made me feel different.
Mahatma Gandhi was not just the man who helped India attain independence. He was a man who showed the world what compassion and love is. You don't need to be an Indian to realize his efforts. You can belong to any nationality, caste, religion and I am sure you will be amazed by the sheer selflessness of Mahatma Gandhi.
Mahatma Gandhi was not talented or skilled. The only gift he had received from the Almighty was his determination and truth. And through these two seemingly ordinary talents he created a new chapter in world history.
Albert Einstein once stated about Mahatma Gandhi that - "Generations to come, it may be, will scarcely believe that such a one as this ever in flesh and blood walked upon this earth."
And this is very true! It is very difficult to beleive that such a selfless person ever existed on this planet, but I know he did and he is the father of our nation.

Tuesday, April 13, 2010

Hi All,

I am new to blogging and this is my first blog.

I would just like to introduce myself here:

I am a SharePoint Developer currently working in L&T Infotech. I have worked mainly in MOSS 2007 and WSS 3.0 and have recently started work in SharePoint 2010. I am planning to use this blog to post stuff on SharePoint and interact with the SharePoint Community.

Hope to post some interesting blogs.

Cheers,

Huzefa Mala.