Welcome to my blog!

Welcome!

You find newly added posts on the right side of the screen. All previously posts are found in the “Archives”, and you can search for keywords in the top right corner of the front page.

How to post code in comments
How to troubleshoot when the scripts does not work
How to use these scripts in a customized form

I have added a Copyright and disclaimer notice here.

Requests are posted in the Request’s post.

Regards
Alexander

59 thoughts on “Welcome to my blog!”

  1. Alexander – I like the concept you are pursuing. I hope you will be posting consistently, at least twice a week. There is a ton that can be done with Javascript and the CEWP, and most people are not aware of it.

    Regards,
    Mark

  2. Hi,

    i am using the Room and Equipment reservation template, where i have start date to be selected.

    what i need is how can i stop users from selected date less than todays date and time.

    thanks for any help.

  3. Hi,
    I’m sorry, but i am not familiar with this template – is it a standard SharePoint “datePicker” you want to restrict?

    Alexander

  4. Here is a quick question on jquery and strings. I have a script that uses google charts. it is a jquery script that uses the calculated totals from a SP list to display the chart. I am trying to add a tag “title” or tool tip that can display the calculated totals for each part of the graph. The script now somehow does a data.join(“,”) with the numerical values. Playing around I found out about the lastindexof(“”). The string var returns a value similar to this:
    “&chd=t:1111,2222”
    When I do the lastindexof I can get the 2222 or I can get 1111,2222 , but I can not get the 1111.
    Do you know how to parse a string? Once parced do I need to convert it to a number or int to apply math functions to it?

  5. Hi larry,
    Try something like this:

    var stringRaw = '&chd=t:1111,2222';
    var numFirstSection = stringRaw.substring(stringRaw.indexOf(':')+1,stringRaw.indexOf(','));
    var numFormat = parseInt(numFirstSection);
    

    Alexander

  6. I really hate to bother you again, but I have spent the last hour looking for how to add to variables. I am pulling my hair out. I found a cacculation plugin, But I am not sure how to tie that into existing code. What the info you provided above I just was to total the 2 numbers so I can return a percentage. besides the jquery site do you know where I can find how to add to variables?
    thank a million!

  7. I was just trying to find an easy way to add (sum) to variables. Once they were parses I wanted to use them in multiple ways to display data. I finally went with this:
    var NC = DataPoints.substring( DataPoints.lastIndexOf(“,”)+1);
    var stringRaw = DataPoints;
    var Completed = stringRaw.substring( stringRaw.indexOf(“:”)+1,stringRaw.indexOf(“,”));
    var Comp = parseInt(Completed);

    var tot = Math.floor(parseInt(Comp) + parseInt(NC));
    var perComp = Math.round((parseInt(Comp)/tot)*100);
    var perNC = Math.round(100-((parseInt(Comp)/tot)*100));

    can this be done in an easier way?

  8. Hi Larry,
    I’m sorry, but i can’t help you here, but if the code works – keep it! You may be able to optimize the code, but in a script like this a millisecond to or from does not matter.

    Alexander

  9. Alexander:
    Is it possible to list all your solutions in a list of posts down the side of your main page here? I love to refer back your blog but sometimes have trouble finding one or two.

    Thanks-
    Charlie Epes

  10. I am trying to combine 2 of your scripts to function in a newform
    AccumulateSelectionsToMultilineText.js and the Dynamic expand/collapse . I found that both have the same function
    function init_fields()

    The problem I am trying to over come is I want to have a field for region, selecting a region with display field for countries in that region. when I put the 2 together I get a funny issue. As I select the first country the fields hide. This goes back to the of having a cascading dropdown and allowing the last field to be a multiple select. This the the functionality I am trying to achieve. Is there a way to run both of your scripts to get the multiple select and hide the fields until a selection is made?

  11. Hi,
    The cascading dropdown script has a attribute “hideEmptyDropdowns”. Set it to false, and your fields is permanently shown.

    Alexander

  12. I would like to make a new request. I am trying to customize a veiw that is grouped and Boxed, with totals (sum, avg, count). the results returned for OOB are not very clean. the top totals just sit in the middle of the page. I would like to remove this row, but looking at the styles and ID its name is shared across multiple rows.

    then the next set of results returned are perfect. it returns the totals for the top level group, and the sub groups. then the format of the individual items are there and not always formatted nicely. I would like to hide the individual items (in orange) and just return the totals for groups and subgroups (in green) like this: http://home.comcast.net/~cookieking/boxed.jpg

    christophe wrote a script for boxed views to use only one column like this.

    <script type="text/javascript"> 
    var boxedview = document.getElementById("WebPartWPQ1").innerHTML;
    boxedview = boxedview.replace(/<td width="1.5%">&nbsp;</td>/gi,"</tr><tr style='font-size:6px;'><td>&nbsp;</td></tr><tr>");
    boxedview = boxedview.replace(/<td width="1%">&nbsp;</td>/gi,"</tr><tr style='font-size:6px;'><td>&nbsp;</td></tr><tr>");
    boxedview = boxedview.replace(/<TD>&nbsp;</TD>/gi,"</tr><tr style='font-size:6px;'><td>&nbsp;</td></tr><tr>");
    document.getElementById("WebPartWPQ1").innerHTML = boxedview;
    </script>
    

    Want to hide top row totals
    have boxed view return one column
    hide row items but still retrive totals

    1. through some CSS I was able to hide the row items and column headers yet still see the totals.
      [sourceocde language=”javascript”]

      #aggr, tr.ms-viewheadertr, #tbod1-1_1__ {
      display:none;
      }

      I am not sure this is the correct way to do this. This grouped boxed view actually has 3 columns probably the reason Christophe script does not work. Trying to expand the totals across the 3 rows and not having any luck. I am going to try to add labels like you did in the SP List form labels script, except add them to the list view. Any suggestions, or resources for this please pass along.

    2. Hi,
      I’m not sure i have understood it right, but try this code in a CEWP below the list view:

      <style type="text/css">
      .customColor{
      	color:red;
      }
      </style>
      <script type="text/javascript" src="../../Javascript/jquery-1.3.2.min.js"></script>
      <script type="text/javascript">
      // Remove top row totals
      $(".ms-stylebox:first").parents('tr:first').remove();
      
      // Remove row items
      $("tbody[id^='tbod1-']").remove();
      
      // Align left by setting width of first TD
      $(".ms-listviewtable td.ms-vh-group").attr('width','1%');
      
      // Set color of first "totals" for sub-groups
      $("td.ms-gb").each(function(i){
      	i = i+1;
      	$("tbody[id='aggr1-"+i+"__'] td").addClass('customColor');
      });
      
      // Hide all empty tbody's to make a cleaner list view when groups are collapsed 
      $(".ms-listviewtable >tbody").each(function(){
      	if($(this).attr('id')==''){
      		$(this).hide();
      	}
      });
      </script>
      

      Regards
      Alexander

    3. wow, that help with 1/2 the changes. thank you so much. do you think it would be possible to add labels? I like your label script because it identified the field and writes a different label for each field. Can thos be done in the list view?

    4. I want to add labels in 2 places. in a group boxed view
      + FieldName: Value (count)
      field1 field1value
      field2 field2value
      …..
      I want to add a label
      after field
      field1: this is my label 1
      field2: this is my label 2

      between Value and (count) – I want the count only to align right, with a label before it like this:

      + FieldName: Value items returned: (count)

      if you need an image let me know.

    5. Not sure if I stated this, I need this for group and sub-group.

      Also can the labels be pulled in from an external list, like your tool tip script? This would make it easier for label updates outside of the code.

    6. Any suggections on how to add a loop and apply the label to each column item? Your script worked great for the first item in Grooup and sub group. But was not able to change it to any of the other items.

    1. Hi,
      Sorry for the late reply, here is my suggested solution (only the bottom part – Changing labels – is modified from the previous code):

      <style type="text/css">
      .customColor{
      	color:red;
      }
      </style>
      <script type="text/javascript" src="../../Javascript/jquery-1.3.2.min.js"></script>
      <script type="text/javascript">
      // Remove top row totals
      $(".ms-stylebox:first").parents('tr:first').remove();
      
      // Remove row items
      $("tbody[id^='tbod1-']").remove();
      
      // Align left by setting width of first TD
      $(".ms-listviewtable td.ms-vh-group").attr('width','1%');
      
      // Set color of first "totals" for sub-groups
      $("td.ms-gb").each(function(i){
      	i = i+1;
      	$("tbody[id='aggr1-"+i+"__'] td").addClass('customColor');
      });
      
      // Hide all empty tbody's to make a cleaner list view when groups are collapsed 
      $(".ms-listviewtable >tbody").each(function(){
      	if($(this).attr('id')==''){
      		$(this).hide();
      	}
      });
      
      // Changing labels
      var arrReplaceLabels = ['01','This is number one','02','This is number two'];
      $(".ms-stylelabel").each(function(){
      	var labelVal = $.trim($(this).text());
      	var arrIndex = $.inArray(labelVal,arrReplaceLabels);
      	if(arrIndex>-1){
      		$(this).text(arrReplaceLabels[arrIndex+1]);
      	}
      });
      </script>
      

      This code is not setup to get the variables from another list, but look here for a method for getting the variables from another list

      Regards
      Alexander

    2. works like a champ. One last question. the second part of each field arr is the text. For simplicity purposes I swapped that with a var str, a different one for each field. This works, but I want to add html. I am actually trying to make it like an ordered list, but it write the html code to the page instead of the format. How can I add html or inline styles to the lables.

      this was truely great, thank you so much. it was worth the wait.

    3. k, i figured out how to convert to html , but not getting the results I need. I changed text to html

      //$(this).text(arrReplaceLabels[arrIndex+1]);
      $(this).html(arrReplaceLabels[arrIndex+1]);
      

      like I stated I want an ordered list this is what I have

      var str1 = "<ol>";
      var str2 = "<li><span>";
      var str3 = "</span></li>";
      var str4 = "</ol>";
      var q01 =  str1 + str2 + "My manager and I have established clear, objective targets and measures for the results I’m expected to deliver." + str3;
      var q02 = str2 + "My manager and I have an effective process in place to handle changes in priorities." + str3;
      var q03 = str2 + "My manager and I make sure my priorities are aligned with the broader organization." + str3 + str4;
      

      with this code it only returns the first item as the ordered list the rest are returned as an unordered list. Where do I need to place the [OL] so I can have some of these returned as part of an ordered list?

    4. Hi,
      I’m not convinced that you can make an ordered list from this. You should see if you could number the elements in the script (by index).

      Alexander

    5. There is a way, a bit messy but it will work. each line will need to contain an open and closed with the addition of the start attribute.

      <ol start="1"><li>This is line one</li></ol>
      <ol start="2"><li>This is line two</li></ol>
      <ol start="3"><li>This is line three</li></ol>
      ...
      

      this will get you the results you are looking for.

  13. Hi there,

    I enjoy reading your site, keep up the good work. I must have clicked on the link to notify me by email and I want to discontinue the email notification as I go directly to the site. I tried the link for the one-click unsubscribe but it does not seem to work. Please help.

    1. Hi Scott,
      I have no control over the subscriptions, sorry about that. Can it be that you subscribe to multiple posts? – that you have discontinued only some of your subscriptions?

      Alexander

  14. Hi Alexander,
    I have been off Sharepoint for a month but am now back at it and eagerly checking your site each day. Happy belated New Year and thanks again for your so generously sharing your knowledge with all of us.

    Marc

  15. Dear Alexander,
    I am Riaz from Bagladsh, This SharePoint JavaScripts blog is really so helpful. i am facing a problem to using javascript in my sharepoint site.
    that is, how can i use javascript in custom List Form web part(using sharepoint designer).
    in default List form web part add a CEWP and write javascript, that’s works fine, but when i try to use custome List Form webpart then it not works.
    please write me the solution.

    Thanking you
    Riaz

  16. In custom list form according to your solutions(How to use these scripts in a customized form) JS works fine, but now i am facing another problem that is, i have two date field (start date, end date) those are default today date set, and a dropdown field(value: yes,no). i want to clear(set null) end date when i select ‘no’ from dropdown list.

    Please write me if have any solution with JS.

    Thanking you,
    Riaz

    1. Like this:

      <script type="text/javascript" src="../../Javascript/jquery-1.3.2.min.js"></script>
      <script type="text/javascript">
      fields = init_fields();
      
      $(fields['MySelect']).find('select').change(function(){
      	var thisVal = $(this).find('option:selected').text();
      	if(thisVal=='No'){
      		$(fields['MyDate']).find('input:first').val('');
      	}
      });
      
      function init_fields(){
      	var res = {};
      	$("td.ms-formbody").each(function(){
      	var myMatch = $(this).html().match(/FieldName="(.+)"s+FieldInternalName="(.+)"s+FieldType="(.+)"s+/);
      		if(myMatch!=null){
      			// Display name
      			var disp = myMatch[1];
      			// FieldInternalName
      			var fin = myMatch[2];
      			// FieldType
      			var type = myMatch[3];
      			// Build object
      			res[fin] = this.parentNode;
      			res[fin].FieldDispName = disp;
      			res[fin].FieldType = type;
      		}
      	});
      	return res;
      }
      </script>
      

      Replace the FieldInternalNames “MySelect” and “MyDate” with your own FieldInternalNames.

      Alexander

  17. Hi Alexander,

    I’m trying to make SharePoint hide a few input fields on a form based on the result of another. This is during the EDIT stage after a List item has been created. Example: if QA = YES then show “QA Data” & “QA Completed By” fields but if if QA = NO then hide them both. Only need this when viewing at form level.

    I can only do this via Javascript with a Content Editor and JS script due to limited server side access.

    I’ve got this code to hide the items – but there is no IF function:

    _spBodyOnLoadFunctionNames.push(“hideFields”);

    function findacontrol(FieldName) {

    var arr = document.getElementsByTagName(“!”);
    // get all comments
    for (var i=0;i 0)
    { return arr[i]; }
    }
    }

    function hideFields() {

    var control = findacontrol(“QA Completed”);
    control.parentNode.parentNode.style.display=”none”;
    control = findacontrol(“QA Completed By”);
    control.parentNode.parentNode.style.display=”none”;
    }

    Any thoughts are much appreciated.

    Thanks,

    J

  18. Scanning some other blogs I came across a neat tool. Thought I would share it here because of the amout of CAML you use in some of your scripts. So far I have not found this tool available for SP 2010, but for us on the older ver shold here, especially on that chart script you have where a custom query can be applied.

    the CAML Query Bulider
    http://www.u2u.be/res/tools/camlquerybuilder.aspx

  19. How can I make the text adjacent to my checkboxes clickable on EditForm and redirect to another list which contains definitions using sharepoint 2007

  20. Can you help me for changing the calendar view on the user permission, I have approved event calendar view and unapproved calendar view, then full control user can see both view and read only see the only approved event view.
    How i can achieve using javascript in CEWP.

  21. Hey Alexander,

    first of all – your blog is amazing and really helping me – i’d wish there were more like this.

    Which brings me to my “requests” – could you might gather more basic information to the “General tips”?

    Id love to know how you teached yourself this stuff – any literature, good blogs, manuals,.. or simply trial&error (like i do:p).

    Furthermore I’ve wondered if there is any way to include an external datasource such as sql into Sharepoint WITHOUT using the sharepoint external datasource/datatypes.
    because those are blocked at my sharepoint, and im also not able to embed an asp .NET-datasource via sharepoint designer – this works until the moment when i save the form/page/whatever – then the designer “discovers an unsecure function” or whatsoever and cuts it out of my code…

    So – at all i wonder if you know a workaround to connect a list with an external sql-database, without using the standard sharepoint options.

    Last but not least one short quesiton – is there a way to edit the excel export method of sharepoint lists? its not possible to export fields with multiple values, such as person/group,… the export simply “cuts” these fields. somehow the sharepoint developers were to dumb to add a simple convert-to-string-method into the excel export…

    Ive made a dirty workaround by setting a hidden field, which synchronizes the “cutted” field – and when i export the list to excel, ive to change the view to see the hidden field – tada. but thats not what i’d call usability, heh 🙂

    anyways, keep on writing!!!

    regards, jan

    1. Hi,
      Glad you liked my blog.

      What kind of information were you looking for in “general tips”?

      Regarding my “education” in SharePoint it’s more or less trial and error. I have never read any SharePoint books, but i have of course picked up some tips in various blogs and discussion forums.

      I cannot help you with external data sources, sorry.

      Regarding the Excel export, i believe this has to do with the version of Excel you have – my 2010 Excel exports multi select user fields without problems.

      Alexander

  22. you have done some amazing things with jquery. I am struggling with a small issue. I am on a sp 2010 publishing site. when you edit the page or check it out for editing you get a status bar with a displayed status. this seems to load after the ribbon, but I cant read the text. my script will fire but always comes back as blank. I have looked all through the page source and searched the net, but I cant find with the meta data value is stored on the page or how to find it. can you or do you know how to identify this value?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.