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
window.attachEvent("onload",InitLoad);
//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");
NewDoc.attachEvent("onclick",HideFields);
//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");
ReSub.attachEvent("onclick",HideFields);
//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");
Expire.attachEvent("onclick",HideFields);
}
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");
RelatedDocs.style.display = "none";
}
}
</javascript>
I’ll continue posting on the use of javascript within Sharepoint, stay tuned :-).
Wednesday, February 13, 2008
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 http://kbalertz.com/947284/declarative-workflow-start-automatically-after-install-Windows-SharePoint-Services-Service.aspx\
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 http://kbalertz.com/947284/declarative-workflow-start-automatically-after-install-Windows-SharePoint-Services-Service.aspx\
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.
Monday, January 28, 2008
Calculated column value disappears after the item gets updated
This does not apply to all calculated columns, just to some of them J.
Here is an example: I’ve had created a calculated column with the following calculated value [ID], initially the column gets populated with the item ID just fine.
After the item gets updated, the calculated value disappears from the field. Here is a little workaround I’ve came up with.
Create a workflow in the SharePoint Designer attach it to your list, workflow should start on item creation, allow this workflow to populate the field with the desired value.
Here is an example: I’ve had created a calculated column with the following calculated value [ID], initially the column gets populated with the item ID just fine.
After the item gets updated, the calculated value disappears from the field. Here is a little workaround I’ve came up with.
Create a workflow in the SharePoint Designer attach it to your list, workflow should start on item creation, allow this workflow to populate the field with the desired value.
Tuesday, January 22, 2008
Action shortcut in tasks list item
This is a small tip which you might eventually find very useful.
This will minimize a number of clicks that users have to do in order to complete the task assigned to them by providing a shortcut to the action described in the task, such as a link to document library’s document upload screen, link to a list’s custom view or an infopath form that user is tasked with submitting .
When you provision a tasks list for your site add a URL type column to the list, you can call it “Action”.
This is how it works, when you create a task (ex: “Please submit your New address information”), populate the “Action” column with URL to the actual form that has to be submitted and into “Description” portion of this URL column put “Action” (this is the display name for your link to the form, use anything you want).
Now when a user clicks on the task, along with the rest of the task properties they see the link that will bring them to the actual activity they have to do, thus minimizing the number of click they otherwise would perform without this shortcut.
This will minimize a number of clicks that users have to do in order to complete the task assigned to them by providing a shortcut to the action described in the task, such as a link to document library’s document upload screen, link to a list’s custom view or an infopath form that user is tasked with submitting .
When you provision a tasks list for your site add a URL type column to the list, you can call it “Action”.
This is how it works, when you create a task (ex: “Please submit your New address information”), populate the “Action” column with URL to the actual form that has to be submitted and into “Description” portion of this URL column put “Action” (this is the display name for your link to the form, use anything you want).
Now when a user clicks on the task, along with the rest of the task properties they see the link that will bring them to the actual activity they have to do, thus minimizing the number of click they otherwise would perform without this shortcut.
Another NLB day
One of my company’s client (with 4 servers in the farm and Cisco Network Load Balancing) had recently experienced abnormal behavior on Shared Services administration site. SSP admin site had started prompting them to login three to five times every time they clicked on some of the links within the site or when they just tried to go to the site itself. When we started looking into this issue it became apparent that they switched from Cisco router to Juniper’s NLB solution, which provides them with more features than Cisco used to do. Shared Services Provider Administration site is NLB balanced and after looking into NLB settings for these web application, we saw that it had compression and acceleration turned on.
We turned it off, both of these options, and the constant challenge for authentication disappeared.
Unfortunately there was not enough time to test, so I can’t tell you which one of these settings was directly contributing to this issue. But it resolved the issue.
We turned it off, both of these options, and the constant challenge for authentication disappeared.
Unfortunately there was not enough time to test, so I can’t tell you which one of these settings was directly contributing to this issue. But it resolved the issue.
Friday, January 4, 2008
SharePoint Beagle!!!
I'm excited to bring to your attention the Holidays present from Bob Mixon to the SharePoint community. The Sharepoint Beagle on SharePoint platform!!!
This is a monthly newsletter featuring articles on Administration, Development and “Real World” section which provides you with real world solutions. Check out the Administration channel where Bob Fox is one of the main contributors, bringing his real life administration experience.
If you would like to sign up for email notifications on the new releases, please click here.
This is a monthly newsletter featuring articles on Administration, Development and “Real World” section which provides you with real world solutions. Check out the Administration channel where Bob Fox is one of the main contributors, bringing his real life administration experience.
If you would like to sign up for email notifications on the new releases, please click here.
Subscribe to:
Posts (Atom)
