How to Categorize a Survey in SharePoint 2010

by Burhan Ramay

A few days back I got a requirement from a client asking me to show highlighted headings and sub-headings of groups of questions in a SharePoint survey. There is no out of box solution available to achieve this functionality. Thus I did a little trick by using JavaScript to achieve the required survey user interface.

 

Requirement

You’ll need SharePoint 2010 Survey having the interface as showing in below image:

Solution

  1. Follow the below steps to accomplish this task.
  2. Go to All Site Content, click on link Create
  3. Select Survey from List category from left side menu, enter Name of survey and click button Create
  4. Add questions in survey and add Single line of text fields for headings and sub-headings e.g. if heading name is Initiation then enter Initiation under Question and select type Single line of text. Do the same for sub-heading
  5. Open SharePoint Designer and Open Site where survey was created in Step 3 above
  6. In SharePoint Designer select List and Libraries from left menu
  7. On right side click on survey name created in Step 3 under Lists column

8. In SharePoint Designer, click NewForm.aspx from under Forms

9. Select Split mode and click inside div underneath Ok, Cancel buttons as showing in below image

10. Type the below JavaScript in code pane above inside div.

<script type=”text/javascript”>

_spBodyOnLoadFunctionNames.push(“hideFieldsOnStart”);

function hideFieldsOnStart() {

//hide the control at start

var control = getTagFromIdentifierAndTitle(“input”,”TextField”,” Initiation “);

control.parentNode.parentNode.parentNode.style.display=”none”;

control = getTagFromIdentifierAndTitle(“input”,”TextField”,”Decision Making”);

control.parentNode.parentNode.parentNode.style.display=”none”;

changeBackGroundColor(control, “Initiation”, true);

changeBackGroundColor(control, “Decision Making”, false);

}

function changeBackGroundColor(control, labelText, isMainHeading)

{

var rows = control.parentNode.parentNode.parentNode.parentNode.getElementsByTagName(“tr”);

for (i = 0; i < rows.length; i++)

{

if(trim(rows[i].cells[0].innerText) == labelText)

{

if(isMainHeading)

{

rows[i].style.backgroundColor= ‘yellow’;

}

else

{

rows[i].style.backgroundColor=’lightblue’;

}

}

}

}

//this gets the field based on title identifier and tagname

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;

}

function trim(stringToTrim) {

return stringToTrim.replace(/^\s+|\s+$/g,””);

}

</script>

11. In the above code, ChangeBackGroundColor() function with false parameter is used for sub-heading and
true for heading

In this code, questions are used as headings and passing as parameters to functions getTagFromIdentifierAndTitle, changeBackGroundColor. Thses headings should be defined as Questions during Survey definition.

Important factor to share this post is to confirm my approach and will be more than happy to know if some other solution is available.

Adjust the column width of a Project Tasks View of a Project Site in SharePoint 2010

Problem

There is no way to fix a Project Tasks View column width permanently in SharePoint. A column width can be changed from heading by using the Configure Columns option but after navigation to other site/library width goes back to its default value. For example if someone wants to show the Resource Name column width 200 pixels instead of default 100 pixels,  then he will need to change column width again and again from the column configuration. Changed width configuration doesn’t persist forever.

Solution

The above mentioned problem can be solved by using JavaScript. Below are steps needed to add script on a page that will adjust required column(s) width.

  1. Open browser and go to Project Site with Project Tasks view
  2. From Site Actions click Edit Page
  3. On page click Add a Web Part

4. Under Categories, select Media and Content;under Web Parts select Content Editor and click the Add button

5. Select newly added web part and click Edit HTML Source under HTML from top menu

6. In the HTML Source editor,add following code and click OK button

<script type=”text/javascript”>

ExecuteOrDelayUntilScriptLoaded(function(){

var oldGanttControl = SP.GanttControl;

SP.GanttControl = function() {

  • oldGanttControl.call(this);

var oldInit = this.Init;

this.Init = function(jsGridControl, jsRawGridData, params){

  • oldInit.call(this, jsGridControl, jsRawGridData, params);

DoCustomizations(jsGridControl); }; };},”SPGantt.js”);

function DoCustomizations(grid)

{

grid.SetSplitterPosition(650);

grid.SetGanttZoomLevel(grid.GetGanttZoomLevel()-1);

var tabl = document.getElementById(‘ctl00_m_g_98b1d4ed_6602_42da_b393_b4e2781c58cd_ListViewWebPartJSGrid_leftpane_mainTable’);

var row = tabl.rows(0);

AdjustWidth(row, 1, “150px”, “149px”, “140px”);

}

function AdjustWidth(row, cellNumber, cellWidth, divWidth, innerDivWidth)

{

row.cells(cellNumber).style.width=cellWidth;

var divs = row.cells(cellNumber).getElementsByTagName(‘div’);

divs(0).style.width=divWidth;

divs(1).style.width=divWidth;

var innerDivs = divs(1).getElementsByTagName(‘div’);

innerDivs(1).style.width=innerDivWidth;

}

</script>

7. In above code function  AdjustWidth(ROW, COLUMN_NUMBER, NEW_COLUMN_WIDTH, NEW_CELL_WIDTH, NEW_DIV_WIDTH);  is calling other function to adjust width of column according to the passing column number as parameter. Other parameters are adjusting cell width and div width contains this cell

Hope this post will give you an idea on how we can hook up the Gantt Control in startup and adjust the column width.

InfoPath 2010 Form Deployment Issue on SharePoint 2010 Environment with Single Web Front-End Server

by Burhan Ramay

Problem

During deployment of InfoPath 2010 form in SharePoint 2010 with one web front-end server I encountered an unknown error which I am going to describe and hopefully will be helpful to others.

Publish form to SharePoint Library through InfoPath Designer

In the publishing process, option Enable this form to be filled out by using a browser is disabled or showing a message like “Publish administrator approved form”. In this scenario, the browser enabled form can’t be published but can be published if someone wants to use client application to fill the form. But web services to access User Profile will not work in any case.

Publish form by using Central Administration

In this situation another option is to publish the form by using central administration. First save the form template by using Administrator-approved form template (advanced). Then upload it through central administration:

When Browse the form template from saved location and hit Upload button I got the following error:

You cannot deploy this solution on this type of server computer as it is configured. This solution must be installed on a server of type: front-end Web server.

Troubleshoot issues with Microsoft SharePoint Foundation.

Correlation ID: 6696fa4c-b682-4f94-8ecf-a0f599245c32

ULS Logs showed the following error:

System.InvalidOperationException: You cannot deploy this solution on this type of server computer as it is configured. This solution must be installed on a server of type: front-end Web server.     at Microsoft.SharePoint.Administration.SPSolutionLanguagePack.CanRunOperationInLocalServer()

 

Solution

It usually happens due to SharePoint loopback check and following are the steps need to be performed on server as a workaround:

  • Click Start, click Run, type Regedit, and click OK
  • In Registry Editor, find registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\LSA
  • Right-click LSA, point to New, and click DWORD Value
  • Type DisableLoopbackCheck, and press ENTER
  • Right-click DisableLoopbackCheck, and click Modify
  • In the Value data box, type 1 and click OK
  • Quit Registry Editor
  • May need to Restart Server