Thursday, February 21, 2008

Saving site as a site template with DataView WebPart

As most of us know that if you create a site out of a custom site template with DataView Web Part on it, the DataView Web Part pages of this site are not going to display properly.

The Error presented in the browser will be like this:
“Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.”

When SP creates the site, it recreates lists, thus assigning a brand new GUID to it.

Sure enough if you open the page in SharePoint designer you will see that the DataVIew Web Part has lost it’s data source because it still refers to the original list’s GUID that it was bound to. But there is a way to avoid this.
And, no, I’m not going to take all the credits for this tip, as it was generously given to me by my colleague, Jonathan Bradshaw (Thank you J).

You can preserve the DataView Web Part data source by binding it not to the GUID of your list but to the List Name instead:

• Open the web part definition in your editor of choice
• Look for all occurrences of ListID in the web part definition and right next to that you should see a GUID.
• Replace ListID with ListName and the GUID with the list name you want to bind to.

It’s that easy.

Wednesday, February 13, 2008

Conditionally hide or show metadata fields in your document library EditForm.aspx

Working for years with web based applications taught me a valuable lesson, put as much as you can on the client side to minimize the number of calls to the server. Javascript comes to the rescue. Never underestimate the power of client side javascript.

Lots of developers and just “SharePoint people” :-) came up with this question: How do I hide or display document library metadata fields depending on metadata values chosen by an end user, such as radio button selection.

Yes, you can open Visual Studio and start developing, I’m all about taking an easy path, it’s not the only one, but in this case it turned out to be the best.

Here is a small requirement that one of our clients had. Depending on a radio button which an end user selects in the document properties, hide certain metadata fields.
First of all you open EditForm.aspx in the browser and view the source code. Locate the radio buttons or your other controls that are serving as the condition for the “Hide/Show” functionality, copy these control’s ID values. In my case it looks like this:

<span class="ms-RadioText" title="New Submission"><input id="ctl00_m_g_6d20c8e6_473d_47f4_bb05_462a9b383491_ctl00_ctl02_ctl00_ctl01_ctl00_ctl00_ctl00_ctl00_ctl00_ctl04_ctl00_ctl01" type="radio" name="ctl00$m$g_6d20c8e6_473d_47f4_bb05_462a9b383491$ctl00$ctl02$ctl00$ctl01$ctl00$ctl00$ctl00$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl01" checked="checked" /><label for="ctl00_m_g_6d20c8e6_473d_47f4_bb05_462a9b383491_ctl00_ctl02_ctl00_ctl01_ctl00_ctl00_ctl00_ctl00_ctl00_ctl04_ctl00_ctl00">New Document</label></span>

I have three radio buttons with the following IDs:

1. New Document=“ctl00_m_g_6d20c8e6_473d_47f4_bb05_462a9b383491_ctl00_ctl02_ctl00_ctl01_ctl00_ctl00_ctl00_ctl00_ctl00_ctl04_ctl00_ctl01”
2. Resubmission=“ctl00_m_g_6d20c8e6_473d_47f4_bb05_462a9b383491_ctl00_ctl02_ctl00_ctl01_ctl00_ctl00_ctl00_ctl00_ctl00_ctl04_ctl00_ctl02”
3. Expired Material=“ctl00_m_g_6d20c8e6_473d_47f4_bb05_462a9b383491_ctl00_ctl02_ctl00_ctl01_ctl00_ctl00_ctl00_ctl00_ctl00_ctl04_ctl00_ctl03”

The same way I’m locating the ID of the field I have to hide. If “New Document” radio button is selected, hide “Related Document” document library field so the user cannot add a value to it.

For the next step, open your EditForm.aspx in SharePoint Designer. Within one of your <asp:Content> add the following :

<script type="text/javascript" language="javascript">
// Initiate InitLoad () function on the load event of your editForm.aspx
//in this function, assign event handlers to your controls
function InitLoad() {
//declaring the first radio button and attaching “onclick” event handler to it
var NewDoc = document.getElementById("ctl00_m_g_6d20c8e6_473d_47f4_bb05_462a9b383491_ctl00_ctl02_ctl00_ctl01_ctl00_ctl00_ctl00_ctl00_ctl00_ctl04_ctl00_ctl01");
//declaring the second radio button and attaching “onclick” event handler to it
var ReSub = document.getElementById("ctl00_m_g_6d20c8e6_473d_47f4_bb05_462a9b383491_ctl00_ctl02_ctl00_ctl01_ctl00_ctl00_ctl00_ctl00_ctl00_ctl04_ctl00_ctl02");
//declaring the third radio button and attaching “onclick” event handler to it
var Expire = document.getElementById("ctl00_m_g_6d20c8e6_473d_47f4_bb05_462a9b383491_ctl00_ctl02_ctl00_ctl01_ctl00_ctl00_ctl00_ctl00_ctl00_ctl04_ctl00_ctl03");
function HideFields(){
var DocType = document.getElementById("ctl00_m_g_6d20c8e6_473d_47f4_bb05_462a9b383491_ctl00_ctl02_ctl00_ctl01_ctl00_ctl00_ctl00_ctl00_ctl00_ctl04_ctl00_ctl00");
if (DocType.checked==true){
// declare my metadata field “Related Documents” to be hidden using the ID from “View Source”
var RelatedDocs = document.getElementById("ctl00$m$g_6d20c8e6_473d_47f4_bb05_462a9b383491$ctl00$ctl02$ctl00$ctl01$ctl00$ctl00$ctl18$ctl00$ctl00$ctl04$ctl00$ctl00$TextField"); = "none";

I’ll continue posting on the use of javascript within Sharepoint, stay tuned :-).

Monday, February 4, 2008

SharePoint Designer workflow does not start automatically.

Here is the thing I just recently ran into. In my portal, there is a site with custom list and a SharePoint Designer workflow that was starting automatically on “Item Update”. All of a sudden I realized that this workflow does not start automatically any more. You could still start the workflow manually, but it’s not a fix. The good part is that I’ve upgraded to SP1 fairly recently and it was not a problem to track back and find out when workflows stop working properly. SP1 had a lot to do with it.This behavior I by design and occurs because of a security fix in Windows SharePoint Services 3.0 SP1, the fix prevents declarative workflows from starting automatically under the system account. After you install Windows SharePoint Services 3.0 SP1, declarative workflows will not start automatically if the following conditions are true:

1. The Windows SharePoint Services Web application runs under a user's domain account.
2. The user logs in by using this domain account.
3. The site displays the user name as System Account.

Here is the link to the solution\

Saturday, February 2, 2008

SharePoint Beagle articles

With the growing popularity of SharePoint Beagle, I’ve decided to start posting a blog entry for each of my articles, the reason is that people with questions or comments about these articles don’t have to seek me out on Facebook, LinckedIn, or send comments to my blog on absolutely irrelevant posts. I’ve received an overwhelming response to the last article “Training Scheduling Solution”, please post all of your questions and comments regarding this article here.