Sharing the same EditForm between different roles

I recently had a client that wanted to show some fields in a form for end users as read only, while Managers, taking a decision, should be able to edit the same fields, all using the same EditForm.aspx.

Ok, so how did I go around getting this to work?

The Managers have Edit permission on the site, while end users have Contribute, this gives the Managers the list permission “Manage Lists”, which end users lacks.

First thing I did was to fire up SPD locating the list and create a new EditForm, let’s call it EditForm2.aspx.
I also created a new DispForm, called DispTrash.aspx (so that I know it should be deleted when I had finished my work).

In your EditForm, locate the top-most field that should be editable to managers, Before its starting <tr> add this:

    <SharePoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl1" runat="server" AuthenticationRestrictions="AuthenticatedUsersOnly" Permissions="ManageLists" PermissionContext="CurrentSite">
    <table class="trimmedContent">

Here will the fields be listed…

After the last field’s end tag </tr> add this:


So we are wrapping the fields with a Security Trimmed Control and a table. this will give the result that the code inside this Control will be hidden for end users.

Now, right after this end tag of the Security Trimmed Control add this:

    <table class="notTrimmed">

Let’s open DispTrash.aspx in SPD, locate the same fields that you wrapped inside this Security Control. Copy the rows and make sure you get the starting <tr> of the first field and ending </tr> of the last field, so that the HTML don’t get messed up.
Paste this code right after this table’s starting tag.
After the last field’s ending tag </tr>, add this:

</table>, to close this table.

Ok, so what do we have this far?

  1. We have two sets of the same fields, where some are editable and the others are display only.
  2. The editable fields are wrapped in a Trimmed Control and will only be shown for users with ManageLists permissions.
  3. This means that the table with the class “trimmedContent” only will be visible to Managers.
  4. And Managers will see both these sets of fields…this must be taken care of!

Locate this row:
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">

Add this code right after this row:

// Hide display fields if security trimmed table exists
if ( $( ".trimmedContent" ).length ) {
    $( ".notTrimmed" ).hide();

This code will check if the table with the class of “trimmedContent” is present. If it is, it means that the user is a Manager and we choose to hide the table that contains the display only fields.

Mission accomplished!

My hope is that this will help someone.



Link to media files on file server

Hi everyone!

I had a client a little while ago that had this requirement.

  • In a list it should be as simple as possible for the users to add a link to a media file that is located on a file server.
  • They did have a mapped net work drive and they were only connected to their Intranet while at office or through VPN.
  • The installation is a SharePoint Foundation

My first thought was to add a default value to a URL column so that they only had to add the last part, but that was not possible.

Then I tried to add the default value to a text column and that worked if it was an http-link but not a file-link.

My friend jQuery came to rescue and offered me a solution that came to be like this.

The idea is that the user, besides adding a few other things in this form, only should have to add the file name and file type e.g. “” in a field to build a link to the file on the server.

Ok, so I found a snippet of a JavaScript (I can’t remember where, sorry) that should be added to an aspx-file and when called, would open up a folder on a shared drive. And that my friends was almost what I was looking for, now I only needed to add the functionality to pick up a parameter and open a file in that folder instead.

First I added a new column “MediaLink” of the type URL. This column should be set to be hidden in the forms, but do that a little bit later.

Then I added a new column “MediaFile” of the type Text with a description of what they should be adding, name and type.

By adding this jQuery code to the edit and new forms, the URL to the JavaScript snippet file, and the value of the “MediaFile” is added to “MediaLink”. At the same time it checks if “MediaFile” is empty, if it is it won’t add the text “Link to media” in the column for that item.

<script type="text/javascript">
$(document).ready(function() {
$('input[title=MediaFile]').change(function() {
var value = $(this).val();
$('input[title=MediaLink]').attr({value: 'http://companyweb/SiteName/SitePages/media.aspx?fileName='+(value)});
if ($(value).length < 1){
$('input[name*="ff81$ctl00$ctl00$UrlFieldDescription"]').attr({value: 'Link to media'});

Be sure to change the URL to media.aspx if you will put it somewhere else. The last part of the attribute “name” you could find by viewing the source of the page, that is before you hide it of course 🙂

Ok so what about that JavaScript snippet, what should we do with that and where is it?

As you can see in the code above I add the parameter “fileName” to the URL of the “media.aspx“. This is the file that should have this snippet that I have been talking so much about 🙂

It looks like this.

  <script type="text/javascript">
//Get querystring
var queryString = window.location.href.split("?")[1];
    var fileName = queryString.split("=")[1];
    // mapped network drive
    var drive = "file://Server/share"
    // folder within the mapped network drive
var folder = "/Folder1/Folder2/Folder3" + folder + fileName, "File");

So, simply add this code to a file called “media.aspx” and put the file in “SitePages”. Be sure to change the variables “drive” and “folder” so that they fit your environment.

I had a talk to Marc D Anderson about this and he gave me a few ideas that I will try to improve this further. When I have, I will update this post with these improvements.

I hope this will help someone!

CU in Vegas in a couple of weeks!

Get a tabular feeling in InfoPath

Hi everyone!

Ok, as the title says I will describe and show you have you could do to give your InfoPath form that little extra that sticks out.

As you already might know we now have the possibility to use pictures as buttons in InfoPath 2010.

The final result will look something like this:

It consists of six pictures altogether, because we have a darker image that will be chosen as hover-button and as the active-button. We also have three views that we can toggle by selecting these tabs.

The tabular area is divided in five cells, a starting and an ending cell and three cells that holds each one of the tabs.

The starting and ending cells both have a background color of RGB: 192, 210, 218 and the cells in the middle have RGB: 205, 219, 225 that will match these pictures. Putting a background color also gives a smoother transition when you hover the buttons.

Start by creating three views named “Requestor”, “Project” and “Financials”.

Then add three picture buttons like this:

For each one of the buttons and cells, set all margins to 0 (zero) so that looks like this.

Now choose the first view, in this case “Requestor” and give the home-button the darker picture and leave the hover button empty.

As you can see InfoPath gives the picture a name of its own.

For the other two buttons in this view, add the brighter picture as its default and the darker as the hover button.

When you have finished all three buttons make a preview to make sure the tabs change when you hover them.

Now we are going to add some rules to the buttons.

On the view “Requestor” leave the first button as is. On the second button add a rule with an action that switches to the view “Project” and on the third button an action that switches to the view “Financials”.

Now do the same thing for the other two views but of course, have their home-buttons dark without a hover button and so on.

Make a preview and make sure you end up in the correct view.



What to do with trailing zeros from SharePoint

Hi everyone!

It’s been a long time since the last post, but sometimes one has to take care of things like the family. Ok, so now when that is done we could start having some fun again 🙂

I would like to start with a small and quick one.

Let’s say you have a drop down (field2) in your form that lists objects from a list in SharePoint. The list has got two columns, Title and Number.

The value for the drop down is set to Number and the Display name is set to Title.

Then you need to set another field (field3) in your form to the value of the chosen object,.

Set the Value of field3 to be same as field2

that’s when you will see that the number of the object will have lots of trailing zeros.

An easy way to get rid of these zeros is to insert a formula in front of the field2 value of sum.

this way the zeros will be gone.

Happy InfoPathing!



CQWP that lists all documents checked out to me

Hi everyone!

I thought I would show you how you could make the CQWP list all documents in your Site Collection that are checked out to me.

The thing is, if you set the CQWP to search the whole site collection or a site for that matter, and then choose “List Type” “Document Library” you will not be able to choose the filter “Checked Out To”.

So how should we do to then?

First of all if you navigate to “Site actions” and “Manage Content and Structure” and then choose “Content and Structure Reports” you will find the reports and the CAML that is used for them. What you should do is to copy the CAML query from the report “Checked Out To Me”.

<Where><Eq><FieldRef Name="CheckoutUser" LookupId="TRUE"/><Value Type="Integer"><UserID/></Value></Eq></Where>

Now, add a CQWP to your page and set it to search a site of your choice, set the “List Type” to “Document Library” and give it a name, chrome type and so on, but don’t set any filters.

Now export the CQWP and open it with Notepad.

Lookup the property “QueryOverride” and replace that row with this one:

<property name="QueryOverride" type="string"><![CDATA[<Where><Eq><FieldRef Name="CheckoutUser" LookupId="TRUE"/><Value Type="Integer"><UserID/></Value></Eq></Where>]]> </property>

As you can see I have already added the CAML from the report for you.

Now save this file somewhere and upload it to the web part gallery.

That’s it!

Now you have a web part you could add that will list all documents checked out to me.



Working with Lookup columns in SharePoint list forms with InfoPath

Hi everyone!

I would like to show you how to work with lookup columns between lists when you would like to summarize the amount of orders that a sales person have made.

So we have a list called “Sales persons” with five columns, “Name”, “Region”, “Office”, “Sales ID” and “TotalAmount”.

We also have a list called “Sales orders” with three columns, “Product”, “Amount” and “Sales ID”.

In this list the column “Sales ID” is a lookup column to “Sales ID” in “Sales person”.

We also have a data connection to retrieve these three fields from “Sales orders”.

When we open a form for a sales person we want to see the total amount of orders that’s been made by that person. When we first look at this it looks quite simple. The “TotalAmount” should be the sum of “Amount” where “Sales ID” equals “Sales ID”, right?

The problem here is when we work with lookup columns it is not actually the value of the look up that is brought to your repeating table by your data connection, it is in fact the “ID” of the item in that list.

So to filter which amounts to summarize we should do like this:

The “TotalAmount” should be the sum of “Amount” where “ID” equals “Sales ID”.

Now when we open the form of a sales person, we could see the total amount that person has sold for.

Hope this helps someone!



Cascading drop-downs and images

Hi everyone!

You all know the great thing with InfoPath, how easy it is to work with cascading drop-downs. I would like to share one more thing with you in this area, how you could show different images depending on your choice in the drop-down.

I will very shortly describe how to set up cascading drop-downs, the main thing here is to give you the way to show the different images.

The drop-downs (2) is received from a SharePoint list with three columns “Tillverkare”, “Modell” and “Bild” (that is Manufacturer, Model and Picture, in english).

The configuration of the first drop-down looks like this.

The second drop-downs configuration looks like this.

Notice the lower circle, the next picture will show what to do when you press the button of the upper circle.

  1. Press the button to choose from your secondary data source
  2. A difference from the first drop-down is that you need to add a filter, so press the button “Filter data…”
  3. Add a filter where you say that Tillverkare (Main data source) is equal to Tillverkare (second data source)


Ok, so now lets move on to how to make this true for an image as well.

My list in SharePoint also has a third column called “Bild” (picture in english) and we want this picture to be changed depending on what Modell we choose.

Now lets add a Picture control to your form and open the properties of the picture.

You will see a default XPath to the picture control it self. Press the button to the right of the XPath and point to your secondary data source and your picture column. Now, as you see where the cross is, we would have wanted a button to add a filter, but it’s gone 😦

Instead we will use the filter from drop-down 2 as I will show you in a minute. For now, highlight your picture column in your data source and press OK. Also notice that you should set the picture to be Read only.

Open the properties of the second drop-down and copy the the part of the XPath that holds the filter.

[xdXDocument:get-DOM()/dfs:myFields/dfs:dataFields/my:SharePointListItem_RW/my:Tillverkare = d:Tillverkare]

Add this at the end of the XPath for the picture control and replace “Tillverkare” with “Modell”. Now you have a filter for you picture control as well.

To avoid having to see the picture controls icon in the form when no “Modell” is choosen, put a formatting rule on it that has the condition “when Modell is blank” hide this control.

When you publish this form you will probobly get an error that looks like this.

But go ahead and publish anyway and you will see that it works.

For a full blog post about setting up the cascading drop-downs you should read this blog post at Koobar’s Point.

I hope this helps someone sometime…