Friday, 21 May 2010

Hide fields of SharePoint Calendar

I wanted a Calendar in my team site without fields 'Recurrence' and 'Workspace'. Since it was production server, i cannot do any custom coding, installation or configuration and even i cannot use any tool to tweak the fields.
So, the solution is to do with JavaScript + CEWP.
Go to the Display.aspx form and EditForm.aspx through an  item in calendar and bring the page into edit more to include the CEWP.

One trick to bring the Displayform or editform to edit mode, just append "toolpaneview=2" after ".aspx" in the address bar of browser
.......DisplayForm.aspx?toolpaneview=2 or
-----EditForm.aspx?toolpaneview=2

Add CEWP to the bottom of page. Add the following script to the CEWP

<script type="text/javascript">
var trs = document.getElementsByTagName("TR");</P><p>
for (var r in trs) {
var row = (trs[r].innerText
trs[r].textContent)+"";
if (row.match(/^Workspace/)) { trs[r].style.display = "none"; }
if (row.match(/^Recurrence/)) { trs[r].style.display = "none";}
}
</script>

3 comments:

Anonymous said...

Thanks, this exactly solves my problem. (can't us SP Designer)

CmdrKeene said...

This is exactly what I was looking for, but it's not working for me. It doesn't appear to be executing this javascript at all. I've made sure the CEWP is below the form on the editform.aspx page. Anything else I should try?

Anonymous said...

You can see if it is executing the java-script by using the developer tools view in IE (hit F12 on your new form page). When it opens hit the 'script' tab to see any errors in the right-hand box.