Pages

Friday, August 26, 2011

SharePoint 2010:No Audience Targeting Option in SP2010 WebParts



Moving of webapplication from one server to another server, everything is working fine except "Target Audience". It is not displaying "Targeting Audience" as "WebPart" properties when edit the webpart.


So to make it enable and visible we do have a few workarounds.  Any one of workaround can fix this problem.

1> Make sure the User Profile Service Application is running and enabled under Service Connections for your target Web Application.  Go to Central Administration>Application Management>"Highlight Your Web Application">Service Connections>User Profile Service Applicatiton.  Ensure that you have a "Started" USPA  under Service Applications. 

2> Activate publishing feature on your site collection.

3> Go to Site Setting àSite Collection Administration à Site Collection Navigation Settings and Make sure audience targeting is checked.


















4> Do a simple "iisreset /noforce" can fix this.

Enjoy!!!!

Thursday, August 25, 2011

Hide the Quick Launch in SharePoint 2007/2010

We do have one requirement in which customized search result page  needs to use full width of the page , it means I need to hide Quick Launch for that page.

There is not any out of the box way by which we can easily hide or make invisible the Quick Launch and the Tree View navigation in SharePoint 2010 sites. 

How to do this?

The easiest way is to do this is
1> Edit the Page by selecting from Site Actions.
2> Add a Content Editor Webpart
3> Add the following text in the HTML Source mode:

#s4-leftpanel{
display:none
}
.s4-ca{
margin-left:0px
}

I applied this logic to pages which are related to Team Site.

See the magic!!!!! :)

Disha Shah

Wednesday, August 24, 2011

SharePoint 2010 :JQuery Magic SPCascadeDropdowns with the same list

Hello Friends


I have this below situation in which all SharePoint lists has been created  and deployed to the production and Users are using this list , their list structure is like this.


First List ,name is "Country" list  which contains "title" field is text field and act as "Country" and "State" field contains name of the State in that country.


Below  is the "City" list in which  we have Country and State as Lookup column and "Lookup" list is "Country" and City name will come under the "Title" field.


Now, on production actual problem has been started when they insert the city inside the list,  because country and state has not been cascading. It is production and people already using it. How to add atleast the minimum cascading so user select the right state depends on country.

Let us use the magic of JQuery.

Here is simple javascript code that I have used to accomplish this.

<script language="javascript" src="/Shared%20Documents/jquery-1.3.2.min.js" type="text/javascript"></script><script language="javascript" src="/Shared%20Documents/jquery.SPServices-0.6.2.min.js" type="text/javascript"></script><script language="javascript" type="text/javascript">

var sCamlQuery = "";
$(document).ready(function() {

// Cascade definition for State dropdown
$().SPServices.SPCascadeDropdowns({
    relationshipList: "Country",
    relationshipListParentColumn: "Title",
    relationshipListChildColumn: "State",
    parentColumn: "Country",
    childColumn: "State" ,
    completefunc: function() {
        sCamlQuery = "<Eq><FieldRef Name='Title'/><Value Type='Text'>" + $("select[title='Country'] option:selected").text() + "</Value></Eq>";
    }
  });
});</script>

After add this script inside the "Content Ediotr Webpart" we have below results, users happy , we happy.























Exact thing what we need!!!
Thanks JQuery!!!

Disha Shah

Tuesday, August 9, 2011

SharePoint 2010: Change the “Add New Item” (and other) messages for a all SharePoint List Types

In SharePoint, to add a new item/document we always have one standard message like “Add a new item”.

Users who are familiar with SharePoint they are used to understand but sometimes users do not understand they have question why I it always has said “ Add a new item”. So to avoid confusion let us add user friendly message.

How to do that? Let us use power of javascript.

Steps:

1. Add a content editor webpart in the page and add this javascript. Add Content Editor Webpart at the end of the page after list.

2. “<script> document.getElementById("idHomePageNewItem").innerHTML="Click here to insert a new country"</script>
This is just the text message for SharePoint Custom List how to make change for each type of list.

Below is list for id for every SharePoint list type.

ID’s used by web parts
SharePoint List Type
Default message
ID for “.getElementById” in the code below
Announcements
Add new announcement
“idHomePageNewAnnouncement” (changed in 2010)
Links
Add new link
"idHomePageNewLink" 
Calendar
Add new event
"idHomePageNewEvent"
Picture Library
Add new picture
“idHomePageNewItem”  *  (changed in 2010)
KPI List
Add new item
"idHomePageNewItem"  *  (changed in 2010)
Tasks
Add new item
"idHomePageNewItem"  *  (changed in 2010)
Project Tasks
Add new item
"idHomePageNewItem"  *  (changed in 2010)
Document Library
Add new document
"idHomePageNewDocument" 
Wiki
Add new Wiki page
"idHomePageNewWikiPage"  
Discussion
Add new discussion
"idHomePageNewDiscussion" 
Custom List
Add new item
“idHomePageNewItem”

Hope this helps!!!
Disha Shah

Monday, August 8, 2011

Read only field in SharePoint EditForm.aspx via Javascript


When we need to make some fields as read only when users wants to edit the item.This thing we can do very easily by SharePoint Designer , open that edit form and create one custom form and edit the field in which we want to make as read only we can change displaymode as edit. But what if do not want to change by SharePoint Designer.
We have very easy way which named as “JavaScript”.
I need to make one field as read-only, here is sample code
Open the editform.aspx page for a list and add one “Content Editor Webpart”, add the below javascript code.
<script type="text/javascript">

function MakeReadOnly()
{
// find all the elements with tag Name as INPUT
var elements=document.body.getElementsByTagName("INPUT");
// loop through all the elements till we find an element with type text and title as name of our field
for (index=0; index < elements.length;++index)
{
if(elements[index].type=="text")
{
if(elements[index].title=="Address") //Field name
{
elements[index].readOnly=true;
}
}
}
}
_spBodyOnLoadFunctionNames.push("MakeReadOnly()");</script>

Hope this helps!!!
Disha Shah

Monday, August 1, 2011

SharePoint : Validate controls before the item is saved via PreSaveAction() in SharePoint 2007/2010

I do have one requirement in which I need to check if they check one of the checkbox then they must have to enter the value. Without eventhandler or any custom code how could we do that?
We can achieve this thing via Content Editor WebPart and write JavaScript inside that. PreSaveAction() is manly used to validate controls before the item is saved( new item or edit).
How to do that?
Let us edit the page and add one content editor webpart , and add the javascript code in that content editor webpart and save page.
Sample of Javascript Code.
<script type="text/javascript">
function PreSaveAction()
{
var control = getTagFromIdentifierAndTitle("input","BooleanField","Other available");
var control1 = getTagFromIdentifierAndTitle("input","TextField","Other Value");
if(control.checked)
{
var StrToCheck= control1.value.replace(/^\s+|\s+$/, '');
//then we check for the length of the string if its 0 or not
if( StrToCheck.length==0 || StrToCheck =='0')
{
alert('Enter the value for Other');
}
}
else
{
control1.value=0;
}
return false;
}
function getTagFromIdentifierAndTitle(tagName, identifier, title) {
  var len = identifier.length;
  var tags = document.getElementsByTagName(tagName);
  for (var i=0; i < tags.length; i++) {
    var tempString = tags[i].id;
    if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
      return tags[i];
    }
  }
  return null;
}</script>

Hope this helps!!!
Disha Shah