Eric’s adventures in Sharepoint, technology, and life.
Email icon Home icon
  • Removing HTML Person Group Fields in Sharepoint

    Posted on October 12th, 2009 Eric 2 comments

    Over on Stump the Panel, Sasha wanted to change the message being displayed on a Tasks list when no one had a task assigned. The hyperlinks for the Assigned To user on the DispForm and EditForm.aspx pages should also be removed.

    First, the Disp/Edit forms. In order to make changes to these pages, we need to employ the tool pane URL hacking method. You’ll need to have a tasks list populated with some data or you won’t be able to see this in action. Click on one of the items to go to the DispForm page. Employ the tool pane hack by appending &PageView=Shared&ToolPaneView=2 to the end of the URL in the address bar and hit Enter. Success, we’re in Edit mode.

    Add a content editor web part. Click the source editor button and paste in the following:

    
    
    

    Substitute a local path to jQuery if it exists in your environment. You may be thinking to yourself that this script looks familiar, well it should. It is the same script from the employee training admin page modifications only repurposed slightly. I have changed the selector to ms-formbody to isolate the HTML Assigned To field. This makes the hyperlink disappear.

    Next step, change DispForm to EditForm in the URL. Add a content editor web part to the page like before. Click the source editor and add the following into it:

    
    

    Now the underline will be gone from the people picker control.

    The original problem was solved by converting the view to an XSLT data view and entering in the default message to be displayed when no items were found. Then Sasha noted that the Assigned To name hyperlink should be removed. This again involved more recycled jQuery code. The XSLT Code for the Assigned To filed looks like this, note we added person as the selector:

    <td class="{$IDADW2OC} person">
    	<xsl:choose>
    		<xsl:when test="@AssignedTo=''"></xsl:when>
    	<xsl:otherwise><xsl:value-of select="@AssignedTo" disable-output-escaping="yes" /></xsl:otherwise>
    	</xsl:choose>
    </td>

    And the jQuery to remove the HTML:

    
    
    

    Post to Twitter Post to Plurk Plurk This Post Post to Yahoo Buzz Buzz This Post Post to Delicious Delicious Post to Digg Digg This Post Stumble This Post

  • Setting read only fields on an Editform.aspx page

    Posted on August 17th, 2009 Eric No comments

    So I was working on a proof of concept assignment that was relatively simple, but thinking about it there was an inherent security issue. The idea for this Sharepoint site is to have a list where someone would register for a research topic. They only get to choose 1 topic. I was going to go about it in a simple way since it’s a POC after all, so it’s just a 2 list solution with a workflow.

    All the research topics are entered on one list, and users will just add their name to the desired topic and save the item back to the list, where Ill do some workflow things and remove it from the list of available topics. Since users have edit rights, I removed the toolbar so they can’t delete it on my custom EditForm.aspx page. The big security hoop is them changing the actual content of the topic and or description.

    This is where my simple solution comes into play. The EditForm.aspx page renders code that looks like this for the Description field.

    
    

    Simply change the ControlMode from Edit to Display, and you have a Read Only field on your Edit page. No jQuery, Javascript, or additional CSS required.

    Post to Twitter Post to Plurk Plurk This Post Post to Yahoo Buzz Buzz This Post Post to Delicious Delicious Post to Digg Digg This Post Stumble This Post

  • Employee Training template, official release!

    Posted on July 2nd, 2009 Eric 50 comments

    After developing this custom template for an internal project, I knew I would have to do some work to be able to recreate and reuse this internally. After a couple weeks of tinkering, deploying and troubleshooting, I have what I believe to be an easily deployable template to manage internal registrations for employee training. After about 10 to 15 minutes of simple configurations, you can have this up and running in your environment.

    All that is needed is Sharepoint Designer access and server access if you wish to deploy the STP file as a top level site in a collection. If not, the file can be uploaded to the Site Template Gallery on an existing collection and deployed as a new site.

    This should be fully WSS compliant, if you have MOSS you can take advantage of the audience features and security trim things a little cleaner. Link to the original template, link to Dessie’s updates and bug fixes.

    I have packaged this into 2 different STP files. Both contain configuration instructions and deployment batch files. One contains HTML emails the other contains more “stock” Sharepoint Designer work flow emails. Choose which ever you’d like.

    P.S. – This looks great with the new Event Planning theme that was released by Microsoft. If you go that route, you’ll want to add some style tags to change the page titles to black so they are readable (and the reason why I included Heather Solomon’s clean calendar CSS file, that theme calendar isn’t styled).

    Edit:7/15/09
    I believe I have tracked down and resolved the problem people were having deploying the template and creating sites and site collections off of it. I have updated the zip file above. For support reasons, I am eliminating the HTML email version of the download. Please refer to this post on how to configure HTML emails. Sorry, it is too difficult to try and maintain 2 different installations and ensure they are all in sync with the bug fixes.

    Post to Twitter Post to Plurk Plurk This Post Post to Yahoo Buzz Buzz This Post Post to Delicious Delicious Post to Digg Digg This Post Stumble This Post

  • Using Information Rights Management and Workflows

    Posted on July 1st, 2009 Eric No comments

    My new article posted on EUSP about how to use the Information Management policy to use a workflow in managing a contract list.

    Enjoy!

    Post to Twitter Post to Plurk Plurk This Post Post to Yahoo Buzz Buzz This Post Post to Delicious Delicious Post to Digg Digg This Post Stumble This Post

  • Employee Training Comments

    Posted on June 25th, 2009 Eric No comments

    Michael Gannotti posted the video that we shot at Sharepoint Saturday Charlotte. If you have any specific questions or comments on how I did something, leave a comment and I’ll get back with you.

    I am hoping to release an updated STP of the template soon.

    Post to Twitter Post to Plurk Plurk This Post Post to Yahoo Buzz Buzz This Post Post to Delicious Delicious Post to Digg Digg This Post Stumble This Post

  • Using Query String Parameters and Surveys pt2

    Posted on May 14th, 2009 Eric No comments

    In part 1, I showed how to pass a query string parameter to a text or number field in a survey. In part 2, I’ll show how to pass it to a look up field. This was utilized in our Employee Training modifications. The look up list for courses can get quite long and have the potential to be named the same, so we wanted to take the guess work out for the registrants.

    To set a query string on a look up list, perform the all the same steps as in part 1, but do not paste that code into PlaceHolderMain. There is a different script to use. Paste the below code into the PlaceHoldermain area, replacing the Field name and parameter names with yours on line 20.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    
    // This javascript sets the default value of a lookup field identified 
    // by <<FIELD DISPLAY NAME>> to the value stored in the querysting variable
    // identified by <<QUERYSTRING VARIABLE NAME>>
    // Customize this javascript by replacing <<FIELD DISPLAY NAME>> and 
    // <<QUERYSTRING VARIABLE NAME>> with appropriate values.
    // Then just paste it into NewForm.aspx inside PlaceHolderMain
     
    _spBodyOnLoadFunctionNames.push("fillDefaultValues");
     
    function fillDefaultValues() {
      var qs = location.search.substring(1, location.search.length);
      var args = qs.split("&");
      var vals = new Object();
      for (var i=0; i < args.length; i++) {
        var nameVal = args[i].split("=");
        var temp = unescape(nameVal[1]).split('+');
        nameVal[1] = temp.join(' ');
        vals[nameVal[0]] = nameVal[1];
      }  
      setLookupFromFieldName("<<FIELD DISPLAY NAME>>", vals["<<QUERYSTRING VARIABLE NAME>>"]);
    }
     
    function setLookupFromFieldName(fieldName, value) {
      if (value == undefined) return;
      var theSelect = getTagFromIdentifierAndTitle("select","Lookup",fieldName);
     
    // if theSelect is null, it means that the target list has more than
    // 20 items, and the Lookup is being rendered with an input element
     
      if (theSelect == null) { 
        var theInput = getTagFromIdentifierAndTitle("input","",fieldName);
        ShowDropdown(theInput.id); //this function is provided by SharePoint 
        var opt=document.getElementById(theInput.opt);
        setSelectedOption(opt, value);
        OptLoseFocus(opt); //this function is provided by SharePoint 
      } else {
        setSelectedOption(theSelect, value);
      }
    }
     
    function setSelectedOption(select, value) {
      var opts = select.options;
      var l = opts.length;
      if (select == null) return;
      for (var i=0; i < l; i++) {
        if (opts[i].value == value) {
          select.selectedIndex = i;
          return true;
        }
      }
      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;
    }

    This helpful tip taken from the Sharepoint Designer Team Blog.

    Post to Twitter Post to Plurk Plurk This Post Post to Yahoo Buzz Buzz This Post Post to Delicious Delicious Post to Digg Digg This Post Stumble This Post

  • Using Query String Parameters and Surveys

    Posted on May 13th, 2009 Eric 4 comments

    Today, in part 1, I’m going to describe how to use a query string parameter within a Sharepoint survey. This can be important for several reasons with the most notable being providing users a hyperlink to submitting a new survey from a work flow email. The hyperlink can have parameters attached to it to pre-populate data that you may not want the user to have to change. In part 2, I’ll describe how to use query string parameters to set Lookup field values.

    The below steps are the same for using a text or number field or a lookup field. What will differ is the code used to populate the fields.

    1. Open the site in Sharepoint Designer.
    2. Navigate to the Lists menu and expand out the survey in question.
    3. Make a copy of NewForm.aspx and rename it to something else, Survey.aspx or Feedback.aspx seem more fitting than NewForm.
    4. Open the newly renamed page.
    5. Delete the stock form from the lower pane.  If you get an error trying to delete it, try expanding the chevron and selecting Default to Master’s Content. Alternatively, set the IsVisable control from true to false. Deleting it could cause problems down the road as noted here.
    6. Click the chevron again and select the Create Custom Content link to create a PlaceHolderMain Custom area.
    7. Click the PlaceHolderMain Custom content area.  Insert a Custom List Form into the page from the Insert -> Sharepoint Controls menu.
    8. Set the top drop down to your survey list and ensure the New item form is selected and click OK.
    9. Click the chevron of this form and click the parameters link.
    10. Create a new parameter with the source being query string and give the parameter a variable name.
    11. Paste the below script into the the PlaceHolderMain area, substituting the Field Name and the parameter name with your values on line number 30.
    12. 1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      
       
      _spBodyOnLoadFunctionNames.push("fillDefaultValues");
      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 setTextFromFieldName(fieldName, value) {
      if (value == undefined) return;
        var theInput = getTagFromIdentifierAndTitle("input","TextField",fieldName);
      theInput.value=value
      }
      function fillDefaultValues() {
       var qs = location.search.substring(1, location.search.length);
       var args = qs.split("&");
       var vals = new Object();
       for (var i=0; i < args.length; i++) {
         var nameVal = args[i].split("=");
         var temp = unescape(nameVal[1]).split('+');
         nameVal[1] = temp.join(' ');
         vals[nameVal[0]] = nameVal[1];
       }  
       setTextFromFieldName("theFormFieldtoPopulate", vals["myQueryStringName"]);
      }
    13. Save and Close the file. Test the form to see if it is in fact accepting your parameter. Navigate to the URL and append ?YourParameter=SomeValue to the end. When you hit enter, the new survey form should appear with the parameter value in the specified field.
    14. Go back to Sharepoint Designer and right click on the survey. Select Properties and click on the Supporting Files tab. Change the New item form to the newly created page by clicking the Browse button and navigating to it. Click OK to apply the change.

    Now this parameter can be leveraged in work flows that email users by creating a URL and grabbing a look up value from Sharepoint list data. This provides 1 click access to users to get to and fill out a survey. In part 2, I’ll describe a scenario where a look up column needs to be populated. For further information, see the Sharepoint Designer Team Blog for other use cases.

    Post to Twitter Post to Plurk Plurk This Post Post to Yahoo Buzz Buzz This Post Post to Delicious Delicious Post to Digg Digg This Post Stumble This Post