Tuesday, September 20, 2011

Enable/Disable Fields using JQuery in NewForm and EditForm.aspx

Hide  fields
$("td.ms-formlabel:contains('Type or Location')").parent().hide();

<script type="text/javascript"
src="/root folder/customization/js/jquery-1.2.6.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var text = $("select[title$='Quotes Attached'] :selected").text();
if(text != "Yes")
$("input[value$='OK']").attr('disabled', true);

$("select[title$='Quotes Attached']").change(function()
var text = $("select[title$='Quotes Attached'] :selected").text();
if(text == "Yes")
//alert('Please attach the Quote by clicking Attach File option');
$("input[value$='OK']").attr('disabled', false);
$("input[value$='OK']").attr('disabled', true);


Please read the below Article

How to Enable/Disable Input element in JQuery

To disable input elements (checkbox, radio button, text box, button etc) in jquery, you need to set disabled attribute.
// check box
$("#check_box_id").attr("disabled", "disabled");
// radio button
$("#radio_btn_id").attr("disabled", "disabled");
// Text box
$("#text_box_id").attr("disabled", "disabled");
// button
$("#btn_id").attr("disabled", "disabled");
To Enable the input elements (checkbox, radio button, text box, button etc) , we need to remove disabled attribute. This can be done in the following way.
// check box
// radio button
// Text box
// button

May times there are requirements like we need to define a field as a required field in SharePoint. Yes, you will say what is new with that? This is built in feature of SharePoint.

Ok, what if I say that field should be mandatory while updating list item but not while inserting the list item. What if I say if value of one drop down in xyz, abc field becomes mandatory?

Well, in scenarios like this we can use jQuery. Yes, jQuery is the answer to this question. Let us put this in to a real scenario.

Ok, before getting into this, I would like to share some steps about this. First we need to handle the change event of drop down. Then we will check the value of the drop down, if the value is suspended, we will pop up one message saying that now because you have selected Suspend status, you must mention the reason for this and we will disable the button OK. We have to do this because there is no way we can stop user clicking ok button unless user writes the reason. Otherwise item will be updated which we do not want.

we also need to handle lost focus event of text area, and at the end we will count the number of characters in the text area. If total comes to zero, well then keep button disabled. If it is not zero and more than zero, then we will enable the button.

Or else we can ask user to select Status back to value which was earlier and enable the button.

Yes, this all steps are required. Try for yourself and you will realize that yes these all steps are required. It may look like some lengthy solution, But remember we did all this stuff right on browser. We never went to write down the code in event handler (this stuff really annoy the end user, as it takes to a different error page, or creating any custom field for this. This is what we wanted and this is the power of jQuery. Isn’t it.

Ok, let us see now in practical

First add the content editor web part above the New Form or Edit Form LVWP where ever you want to place the logic.

This is the layout of my editform.

Add the following code to the content editor web part. Do not forget to reference appropriate jquery file from your library.

<script type="text/javascript" src="{site URL}/Shared%20Documents/jquery-latest.js">

$(document).ready(function() {
//Below function makes sure that if the status is not suspended in edit mode, it disables the reason text //area
var text = $("select[title$='Status'] :selected").text();
if(text != "Suspended")
$("textarea[title$='Reason'] ").attr('disabled', true);


Below function makes sure that when the status drop down is changed to suspended status, reason textarea becomes enabling to write down the result and disabled the OK button unless user enters the reason. If suspend is not selected, again disable the reason field and enable the OK button.


var text = $("select[title$='Status'] :selected").text();

if(text == "Suspended")
alert('you must provide reason for suspending this order');
$("input[value$='OK']").attr('disabled', true);
$("textarea[title$='Reason'] ").attr('disabled', false);
$("input[value$='OK']").attr('disabled', false);
$("textarea[title$='Reason'] ").attr('disabled', true);


Finally below is the blur event of the reason field, which checks if anything is entered in reason field or not. If not keep the button OK disabled, or else if something is written enable the button.


var text = $("textarea[title$='Reason'] ").text();

if(text.length <= 0)
$("input[value$='OK']").attr('disabled', true);
$("input[value$='OK']").attr('disabled', false);




So here is the result of it.

See below image as status is not suspended I am not able to type in anything in reason field.

Below figure shows when I changed the status to Suspended, it pops up message and disabled the ok button after message is displayed.

After mentioning the reason, OK button enables.

That is it. You have just made required field validation without using any custom field or writing event handler.

Thursday, September 15, 2011

Custom Form – Edit Fields Based on Permission Levels in SharePoint (Screencast)

There are situations where certain fields in lists or libraries need to be hidden or displayed according to the permission level of the logged in user.  Since there is really no out-of-box way to assign permissions to fields, here's a way to do it using conditional formatting in SharePoint Designer.  This is my favorite SP Designer trick, that I discovered a few months ago.
See my reference (Ian's SharePoint Blog):
In this example, the field called "Priority" needs to be hidden from everyone except for those users who have rights as approvers on this custom list.  Also, there is a field called "Audit Date", that only approvers need to be able to edit, but other users (even those with edit rights) should not be able to edit this field, and everyone can see it.
Doing this entails creating custom forms for all three forms (NewForm, DispForm, and EditForm) in the list.
Here goes...
1.  To keep this simple, create a custom list called "Policies" on your site.  There are 4 fields: 
Policy Name (changed from the default Title field)
Priority - multiple choice
Notes - multiple lines of text
Audit Date - date/time

2.  Create a blank web part page in the same site collection as the Policies list.  It doesn't matter where you save it, since we'll be deleting it later.
3.  Open this web part page in SharePoint Designer.  Click on "Click here to insert a Web Part".  This is really just to make sure that you insert this web part into a web part zone, and not some random spot on the page.
4.  On the <Insert> menu, choose SharePoint Controls, then Custom List Form.
5.  Pick the Policies list, then choose New Item Form.  OK
6.  Select the entire table row that contains the Priority field.  This is the field that we want to hide from everyone except approvers.  On the <Data View> menu, choose Conditional Formatting.

7.  In the Conditional Formatting screen on the right, click <Create>, and choose <Show content>.  On the Condition Criteria screen, click <Advanced...>

8.  Select IfHasRights from the list of functions, and then put the number 16 in the parentheses.  To see where I got the number 16 (approver permissions), click on the link to Ian's blog above.  Click OK.  Click OK again.

9.  Next, the Audit field needs to be only editable by list approvers.  So, since this is the new item form, we'll just hide it from everyone else.  So, select the Audit Date row, and put the exact same condition on it with conditional formatting.
10.  Save this page.  It's okay to customize it from the site definition.
11.  At this point, it does help to have some data in your form, so go ahead and create a couple of list items.
Also, I'd like to note that when using custom forms like this, the Attachment button doesn't work anymore.  I think there are blogs somewhere about this bug, but I've never tried fixing it.
12.  Create a new, blank web part page in the same place you created the first one.  This will be the EditForm page.  Repeat steps 3 & 4.  Then, this time when inserting the Custom List form, select "Edit item form".
13.  Repeat steps 6, 7, and 8 on the priority row.
14.  Next, we essentially need to make two copies of the Audit Date field.  We want it to be editable to list approvers, and visible (not-editable) to anyone else.  Create a new row in the table.
15.  Put the text "Audit Date" in the left cell, and put the cursor in the right cell.  In the <Data Source Details> pane on the right, select the Audit Date field, then click Insert selected field as --> Formatted --> DateTime.  Then, you can opt to uncheck the Time check box, and click OK.
16.  Select the row of the editable audit date field.  For the conditional formatting, only show the content when IfHasRights(16).
17.  Select the row of the read-only date field (the one that was inserted in step 15), and create a conditional formatting rule to HIDE content when IfHasRights(16).
At this point, since you most likely have full control permissions on this list, this row will seem to disappear!  While you're doing this design work and showing/hiding fields, you can go to the Conditional Formatting pane, and click Set Visibility and choose All Formatting hidden.  This will let you see the field you just hid.  Be sure to set it back to default when you're done.
HANG in there, only one more form to go.
You know the drill... create another blank web part page...
When you insert the custom list form this time, choose "Display item form"
All we have to do on this one is create a conditional formatting rule that will show the content IfHasRights(16)
NOW, it's time to save each of these data views as web parts.  Go to the browser, and navigate to the library where you saved the 3 web part pages you just created.  Open each page export the web part.  Save the *.webpart files to your desktop or whatever.  In the filename, be sure to indicate whether it's New, Edit, or Display.
In your Policies list, create 3 new, standard views, and call them "New", "Edit", and "Disp".
On each of these new views:
- click <site actions> and <edit page>.  Delete the default list view web part.  Be sure to delete it, not just close it.
- Import the associated web part from your desktop.
- Exit Edit Mode
Now that there are 3 new forms in the Policies list, the last thing to do is associate them correctly. (I think that's the right terminology).  Anyway, go back to SharePoint Designer.
In the left pane, under the Lists folder, right click on the Policies list, and choose "Properties".
Click the "Supporting Files" tab.  Change the content type to Item.
Change each of the 3 supporting files to your new Edit, Display, and New aspx files.
Fun!  Now test it!
Once it's just the way you like it, then you can delete those 3 original web part pages that you exported from.  Check it out, we didn't leave anything unghosted!
Here's my screencast based on this blog: http://www.screencast.com/users/EndUserSharePoint/folders/SharePoint%20-%20Data%20View%20Web%20Part/media/20020452-c3c9-45f1-96fc-4a51ae1a627d

Please use the Video :


Wednesday, September 14, 2011

SharePoint Server 2007 server farm topologies

Different type of SharePoint Server 2007 server farm topologies. (System Architecture)

This article discuss about understanding the different type of SharePoint server farm topologies.
The SharePoint Server 2007 server farm design vary based on the customer requirements, security perspective and size requirement. The topology designs can be created based on the size of the server farm namely small, medium, and large which can focus on either a single or multiple farm models.
Different type SharePoint Server Roles
Web Front End Server : A front-end server that provides the web services used to render applications (Presentation layer).
Application Server : A front-end server that provides applications services such as search and index (Services layer)
SQL Database Server : A dedicated server running either Microsoft SQL Server 2005. In large farms, this is typically a SQL Server clustered configuration with two or more servers.
Domain controller : Provide authorization and authentication service to Office SharePoint users.
Small server farm :
Small server farm which consist of two-server, one of the servers hosts the Web front end and the application services, while the second server hosts the SQL Server database. This provides a way to manage the database separately but adds complexity without adding scalability or availability.
This type of smallest deployment that is recommended for demonstration, training environment or very small organization or user group.
If you notice that architecture diagram has domain controller, either demonstration environment or very small group, I am sure that there will be existing domain controller server, you may consider re-use.
Small Farm System Architecture
Medium server farm :
Part of this article is to help you determine the minimum requirements which allow you design and achieve your customer goal.
To design high-availability solution, you must deploy a server farm. To decide you may need to discuss following items with your customer and analysis the outcome.
Question Yes No
Is your overall availability requirement below 99%?  
Is the availability of your data critical?  
Question 1 Is your availability requirement 99% or greater? If your customer response to “YES”, which means organization looking for high availability on Office SharePoint Server 2007.
I order to meet above requirement you need to design your Web Front End Server to the two-server deployment, which will gain scalability and availability by load-balancing requests so that if one server goes down, the system up and running.
Question 2 Is the availability of your data critical?, If your customer response to “YES”, which means organization is looking for high availability and gain scalability to safe from data loss, so your design need to be clustered or mirrored database server .
Medium Farm System Architecture
Large server farm :
Part of this article is to help you determine the Large server farm configuration which is suitable for an enterprise-level SharePoint environment:
To design enterprise-level SharePoint environment, you may need to discuss following point with your customer and analysis the outcome (This question are in-addition to medium farm server questions).
Application server role Service
Excel Calculation Services 
Index & Search (External System i.e. ERP, CRM, File share and Lotus Notes)  
Windows SharePoint Services 3.0 search 
Enterprise-level SharePoint environment :
_ Two or more load-balanced front-end web servers running Office SharePoint Server 2007
_ Two or more application servers running Office SharePoint Server 2007
_ One Index & Search servers running Office SharePoint Server 2007
_ Two or more clustered database servers running SQL Server 2000 or 2005
_ SAN Storage
The above architecture diagram shows Web Tier, Application Tier and DB Tier which design to serve different purposes, each of the servers provides specific SharePoint Server 2007 services such as Index Services or Excel Calculation Services, and the front-end servers provide web content services.
The servers in server farm (WFE server, Application server, Index server) must run with Office SharePoint Server 2007.
Database server which configure clustered or mirrored environment with SAN storages.
There is nothing special or difficult on above architect design, basically understanding the customer requirements (i.e. future user growth rate, storage capacity, system availability, security, and system performance requirements) put this pieces of information together and analysis and provide possible solutions architecture that meet your customer goal

Setup and Install SharePoint 2007 Server (MOSS) on Virtual PC


This article describes how to Setup and Install SharePoint 2007 Server (MOSS 2007) on Virtual PC


Microsoft Office SharePoint Server 2007 is a powerful technology which consists of Document management and collaboration websites.
Before you start installing, Make sure that you downloaded following software’s.
  1. .NET Framework 2.0
  2. .NET Framework 3.0
  3. Windows SharePoint Service 3.0
  4. Windows SharePoint Service 3.0 SP 1
  5. Virtual PC 2007 and
  6. Windows Sever 2003 R2.
The following process includes creating a new VM definition, adjusting the settings, and installing the operating system (OS) and .NET Frameworks. (Take note that this process will take about three hours.)

Setup Victual PC

1. Click New... and Click Next

2. Select Create a new virtual machine. Click Next.
3. Type the name and location. The default is New Virtual Machine. To create the VM on your external hard drive, enter the location and a name called WindowsEntServer2003BaseImage. and Click Next.


4. Select an operating system as Windows Server 2003 and Click Next.
5. Adjust the RAM. For this base image 1 GB or 1024 MB will suffice and Click Next.
6. Select A new virtual hard disk option and Click Next.
7. Create the hard disk in the same location that you selected in step 4. Adjust the virtual hard disk size 6 GB is a good start. You can resize the disk at any time and Click Next.
8. Click Next and Finish to completed the process.

Setup Loopback Adapter

Once the machine is created, add a second network adapter on the virtual machine to your host machine's Loopback Adapter.
1. Click Settings.
2. Click Networking.
3. Change the setting Number of network adapters to 2.
3. Incase if you do not know how to Install Microsoft Loopback Adapter. Go to this website and follow the steps to install (How to install the Microsoft Loopback adapter in Windows XP)
4. Change the setting Adapter 2 to Microsoft Loopback Adapter.
5. Click OK.

Install an operating system on Virtual PC.

1. Virtual PC, click Start
2. If you have a Windows Server 2003 Enterprise R2 CD or DVD, insert it in your host machine now. If you have a Windows Server 2003 Enterprise R2 ISO image file, Go to menu bar, click CD, then Capture an ISO Image, and browse to the location of your Windows Server 2003 Enterprise R2 ISO image. Open the image.
3. Follow the instructions to install the server operating system.
4. In the pop-up, select Notepad. Click OK.
5. Add the IP address and machine name of your virtual machine on a blank line.
6. Close the Window, and click Yes when prompted to save the changes.
Once everything done, then the OS need to activate and Windows Update is run to install all available service packs and patches.

Edit the HOSTS File

Since the virtual network will not going to be served by the same DNS server used by the host machine. You need to locate a virtual machine by name rather than IP address, To edit Host file follow the steps.
1. Got Run and enter C:\WINDOWS\system32\drivers\etc Right-click the HOSTS file and select Open.


2. In the pop-up, select Notepad. Click OK.
3. Add the IP address and machine name of your virtual machine on a blank line.
4. Close the Window, and click Yes when prompted to save the changes.

Install ASP.NET 2.0 and ASP.NET 3.0

ASP.NET and Windows Workflow Foundation (WF). Both are required by SharePoint. ASP.NET 3.0 package Include above items, So follow the steps to Install.
1. Copy .NET setup file to your VPC or Share folder and access form VPC
2. When you double click it prompted to Run, Open, or Cancel, click Run or Open.
3. Prerequisites will be checked and files will be copied.
4. Agree with the terms, accept the license and click Install.
5. When installation is complete, click Exit.

Allow ASP.NET 2.0 Web Service Extensions in IIS

1. Select Start - Administrative Tools - Internet Information Services (IIS) Manager
2. In the Internet Information Services management console, expand the server name in the left pane, then select Web Service Extensions:

3. In the right pane, select ASP.NET v2.0.50727, then click the Allow button:

Install Windows SharePoint Service 3.0 SP 1

1. Copy .NET setup file to your VPC or Share folder and access form VPC
2. When you double click it prompted to Run, Open, or Cancel, click Run or Open.
3. Agree with the terms, accept the license and click Install.
4. When installation is complete, click Exit.

Back Up Your Base Image

Congratulation... Now you have created a reusable base image. Start to make a backup this image. So that you can save time when creating servers in the future.
1. Click Start and Shut down your VM. Enter a reason of "Base Image Backup".
2. Once the files are backed up, you can create a new machine by moving or copying the VHD into another folder, renaming it according to purpose
3. Prerequisites will be checked and files will be copied.

Install SharePoint on Virtual Machine

1. Virtual PC, click Start
2. If you have a SharePoint 2007 Server with Service Pack 1 CD or DVD, insert it in your host machine now. If you have a SharePoint 2007 Server with Service Pack 1 ISO image file, Go to menu bar, click CD, then Capture an ISO Image, and browse to the location of your Windows Server 2003 Enterprise R2 ISO image. Open the image.
3. Follow the instructions to install the server operating system.
4. Insert the MOSS 2007 installation media, start the installation, enter the Standard / Enterprise product key, then click the Continue button:
5. Select I accept the terms of this agreement checkbox, then click the Continue button:
6. On the Select the installation you want screen, click the Advanced button:
7. Server Type tab, select the Complete option and then click the Install Now button:
8. Once the installation is complete, select the Run the SharePoint Products and Technologies Configuration Wizard now checkbox, then click the Close button
9. Run and SharePoint Configuration Wizard
10. On the Welcome to SharePoint Products and Technologies screen, click the Next button:
11. In the services may have to be started or reset dialog box, click the Yes button:
12 On the Connect to a server farm screen, select the No, I want to create a new server farm option, then click the Next button:
13. SharePoint Setup will complete 1of10 steps to auto configure
14. Congratulation.. You installed and configured MOSS 2007 application running inside the virtual machine.