Friday, June 10, 2011

Change Add New Item Text of List View Webpart

When I came across this problem, I have found some solutions that uses javascript i.e. got the id of the “Add new item” link and change its text. But after sometime I have found another solution which uses SPD 2010. So, here is the solution:
  • Open Page in SharePoint Designer 2010
  • Open List and then choose the View on which you want to change the text.
  • Switch to Design mode and select List View web part.
  • Now You should see List View Tools on SharePoint designer ribbon, select Design from it.
  • There is a section called “Toolbar”, and an “option” dropdown is there, change options from “None” to any other option. Now You should see “Add New Item” link on Design View.
  • Select “Add New item” and click just after this link and wait for the vertical cursor to appear, this will cause the web part to Load on that page.  SharePoint Uses Web parts references on the pages and the data with the web part is rendered at runtime.
  • When cursor appears, just press any key so that it gets written on that page. Now Switch to code view.
  • Delete the key that you have pressed :)
  • Now look just before the cursor (where you have delete the pressed keys),  you may have the following code in front of you:
               <a class="ms-addnew" id="{$ID}"
                 href="{$Url}"
                 onclick="javascript:NewItem2(event, &quot;{$Url}&quot;);javascript:return false;"
                 target="_self">
                <xsl:value-of select="$AddNewText" />
              </a>
  • Remove “<xsl:value-of select="$AddNewText" />” and write your text that you want to display on the link.
  • Save the page.
View Page in your browser and verify the changes.
Happy Exploring SharePoint !!

Friday, June 3, 2011

Switching Infopath Views based on User Departments

During Sharepoint intranet portal development, i have experienced a problem that i need to display infopath forms differently to different departments (as a common Intranet portal have departments in it).I have noticed that the production environment haven't setup correctly i.e. User profiles were not synchronized by the sharepoint administrator and hence, the sharepoint user profiles doesn't have complete information of the users. 

I have overcome this problem by doing the following steps:
1- create security group for that particular dept
2- follow the steps of this link
http://blog.ianchivers.com/2011/01/using-sharepoint-usergroup-web-service.html 
and make a data connection "D1"
3- Now add a choice field in infopath form.
4- set its default value like this
boolean(@ID[@LoginName = concat(substring-before(@LoginName, "\"), "\", userName())])
where,
ID = D1 -> Data fields -> .... -> ID
LoginName -> D1 -> Data fields -> .... -> LoginName
boolean(), concat(), substring-before() and username() are the builtin infopath functions

Now On FormLoad Event, if choice field value equals your desired value, then switch the view...