Thursday, May 17, 2012

Set default field value using SharePoint Designer


We can set a default field value in SharePoint. But if we want to pass a field value with parameter and then set field value then we have several option. One of them if use jQuery and set the field.


The other one is the one that I am going to show you in this post and that is through SharePoint Designer.

I have one dummy list just to show you how this work. This list has two dates. One start date and the other end date. We are going to pass two dates as parameters and then set those dates with the values. Both are date time fields.

The idea is those two dates should be disabled and cannot be edited by the end user plus they should have default value set passed by query string.

Now open SharePoint Designer 2010 and connect with the site. Note that this can also be done using Designer 2007 for MOSS 2007 / WSS 3.0 sites.


We are going to create a new form and have that new form as default new form. We will not make any changes to the actual new form.

Click on New



Configure properties like this



Now we have set the new item form for us and we have made it default form for new item instead of built in newform.aspx



Now click on that new item form that we’ve just created.

Page opens in HTML and design view. Now the idea is we need to remove the entire web part and to remove it. Select the entire web part and click delete that web part.



You will have something like this



Place cursor where highlighted and then click on Insert tab, custom list form.



Select Default Value Check list and new form and then click on ok. We are adding custom list new form now on this page instead of the default new page.

Now you’ll get this



Select start date and change it to a text box, do that same for end date.



You will observe a change in HTML code. Both have turned in to textboxes now.



Select both textboxes and check properties and select enabled to false for start date and end date.



We are yet not done with this. We now have to create parameters first. First save the form.
Click on options and the parameters from the ribbon



We need to create two parameters one for start date and the other for end date.



Configure it like this





Now we need to set these parameters with start date and end date fields on the form. Locate the start date text box in HTML and check out the text property.



Change it to this. This is the name of the query string and not the query string variable. Query string variable needs to be passed in URL.



Do the same for end date.

Save the form now.

And now go back to actual form via browser and pass on Start and End as parameters and you are done.


1 comment:

Anonymous said...

Thanks you!!!!




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com