in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Marian Lishman's Blog

From STS to WSS and beyond :-)
  • No more comments

    I have now disabled comments on this blog as I am starting to get an unmanagable number of spam comments. If you wish to contact me then please send me a personal message through sharepointexperts.com - my username is lishmanm.
  • Printing just the web part (not the stuff round it)

    (Reposted due to undeletable spam comments)

    So I have created a web part that is a calulation based on various fields in various lists on the site. It displays a table full of data and some text stuff. The client wanted to be able to print just what could be seen in the web part and not all the nice looking stuff around it.

    It took me a while to figure this out and it was with the help of this link:

    http://personalweb.about.com/od/copypastejavascripts/a/404_3scripts_3.htm

    So I was lucky in the fact that my output was just a stream of html so I put div tags around the stuff I wanted to print like this - <div id='printPart'> print this bit</div>

    and then just added the code to the head of the page (must do this in FrontPage) where the webpart was like this:

    <script>

    function printSpecial()

    {

    var html = '<HTML>\n<HEAD>\n';

     

    if (document.getElementsByTagName != null)

    {

    var headTags = document.getElementsByTagName("head");

    if (headTags.length > 0)

    html += headTags[0].innerHTML;

    }

     

    html += '\n</HEAD>\n<BODY>\n';

     

    var printReadyElem = document.getElementById("printPart");

     

    if (printReadyElem != null)

    {

    html += printReadyElem.innerHTML;

    }

    else

    {

    alert("Could not find the printPart div");

    return;

    }

     

    html += '\n</BODY>\n</HTML>';

     

    var printWin = window.open("","printSpecial");

    printWin.document.open();

    printWin.document.write(html);

    printWin.document.close();

     

    printWin.print();

     

    }

    </script>

     

     It all needs a bit of fine tuning but in essence it works a treat!

  • Filtered Dropdowns in Newform/Editform

    Ihave been working on populating a field with items from another list depending on what I pick in the previous field and have got a bit further on. I now have a list where one of the lookup fields fills depending on what you have picked in the previous field.

    Here is the code that I am using: note that I use a button to call the script as I put this in the editform and if I leave the code on the onblur event it will remove any existing data that I have in the filtered lookup that may already be correct.

    <script>

    function RepopulateList(fieldValue)
    {
    // -- retrieve the list for the elements
    var siteName = "http://www.xyz.com/site";
    //the next field is the name of the field that you want to appear as filtered
    var controlName="urn:schemas-microsoft-com:office:office#Control";
    //this is the list GUID of the second list that you are picking up the filtered data from
    var lookupListName = "{99E28AFE-5643-4F69-AF52-DE3DB3D563D2}";
    //this is theGUID of the view in that second list - create a view that has ID and the items you wish to filter (in that order)
    var lookupViewName = "{1D516144-CA30-4BCD-A742-E8F2BB8EA863}";
    var listEl = document.getElementsByName(controlName)
    // -- emptying the field that you want to filter
    if(listEl.length>0)
    {
    listEl(0).innerHTML = "";
    // -- getting the filtered lookup filterField is the name of the other field that the filtered list is dependant on (i.e. mine picks controls that are relevant to the workstream I have selected)
    var filterField = "Workstream";
    var filterValue = fieldValue;
    var reqstring = siteName + "/_vti_bin/owssvr.dll?CS=109&XMLDATA=1&RowLimit=0&List=" + lookupListName + "&View=" + lookupViewName +"&FilterField1=" +filterField + "&FilterValue1=" + filterValue;
    var req = new ActiveXObject("MSXML2.XMLHTTP");
    req.open("GET",reqstring,false);
    req.send();
    // -- loading response in XML Document
    var doc = new ActiveXObject("MSXML2.DOMDocument");
    doc.loadXML(req.responseText);

    var data = doc.documentElement.childNodes(1);
    //this loops through the items picked up from the list and puts them in the filtered dropdown
    for (i=0;i<data.childNodes.length;i++)
    {
    var optionText = data.childNodes(i).attributes(1).value;
    var optionValue = data.childNodes(i).attributes(0).value;
    var opt = document.createElement("OPTION");
    listEl(0).options.add(opt);
    opt.innerText = optionText;
    opt.value = optionValue;
    }
    }
    }
     </script>
     
     <script language="javascript">

    var workstream1 = document.forms[0].elements["urn:schemas-microsoft-com:office:office#Workstream"];
    function getCA_onclick()
    {
    alert("The Control dropdown will now be repopulated, please select the correct one");
    var chosen = workstream1.options[workstream1.selectedIndex].text;
    RepopulateList(chosen);
    }
    </script>

  • Filtered lookups - creating data in excel

    I was trying to come up with an idea that would make filtered lookups so that only a select number of items in a lookup would appear. For example if you had non-active data in a lookup and only wanted to be able to select from the active ones, but you obviously couldn’t delete the data from that lookup as it would appear in old linked items.

     

    The added problem is that the users were adding the data from excel rather than uploading the new form (I had already written some suitable code for this).

     

    Anyway, with this in mind I thought the following might come in useful for someone else. It is an excel spreadsheet that has the lookups built in and those lookups are linked to the site although the main list is not linked to the site (because then you couldn’t choose where the lookups are selected from) and the data needs to be pasted in in datasheet view.

     

    The lookups themselves would need to be linked exports from the look-up lists. You will firstly need to set up a filtered view of the data you wish to see in your lookup. Export this particular view to your spreadsheet and then use it as your lookup for that row of data (use data validation).  When the spreadsheet opens the data would need to be synchronised with the list. This could be done by writing a macro that went through and synchronised them all. It may be necessary to turn macros on for the person who is running them. You can set up the spreadsheet to run the macros on opening.

     

    Then you have a list that looks up to only the data you want it to.

     

    Code for automatically running the macro on loading the sheet:

     

    Private Sub Workbook_Open()

    Run ("Synch_Data")

     

    End Sub

     

    Code for synchronising the lists:

     

    Sub Synch_Data()

      

        Sheets("Data").Select

        Range("BA2").Select

        ActiveSheet.ListObjects("List1").UpdateChanges xlListConflictDialog

        Sheets("GapTypes").Select

        Range("B2").Select

        ActiveSheet.ListObjects("List1").UpdateChanges xlListConflictDialog

         Sheets("Data").Select

        Range("A1").Select

     

    End Sub

     

     

  • Personalised Navbar

    You can have a personalised navbar for each person by creating a list of the links and then entering the links for each person that you want to see in the navbar. Create a dataview that mimics whichever navbar you wish to have personalised (for example you can insert a row next to the top navbar, hide that and then customise your list view to look like that.) If you have view only my own switched on then each person will see their own navbar selections. The downsides are that if you are an admin you will see multiple navbars (unless you set maximum number of items to be 1) and you either have to enter the data as that person or get them to enter it themselves.

     

  • Putting totals in for a field that is a calculated one


                   
                   
           
           

    For some reason I don't seem to have the option of formatting this as a number in FrontPage so I guess I will need to do that in the XSL as well.

    I have often thought it a bit strange that you cannot total a calculated field, particularly when it is a number. I managed to acheive this a while ago but had forgotten how I did it so now I am going to put in down in writing so that I don't forget!

    You need to change the view to a datasheet one in Frontpage. Then go to the code and find the ??? that ends the display of all the data. Between that and the ??? enter another row and the required number of table cells.

    Then add the xsl code that will sum that field - in my case this makes the xml like this:


               

    Total Cost: <?xml:namespace prefix = xsl /><xsl:value-of select="sum(<A href='$Rows/@TotalCost)"></xsl:value-of>$Rows/@TotalCost)"/>>
               
  • Problems with custom link bars

    When adding a custom link bar through FrontPage it basically just doesn't appear on the page in IE. Can't yet figure out why not.
  • Problems with submitting forms

    We are having problems when some external uses (extranet site with SSL) are clicking submit on a form. Basically they just get a blank page with the URL http://server/site/_vti_bin/owssvr.dll?CS=109 - I assume this is something to do with their IE settings being on possibly too high a security setting but am not sure at the moment. Maybe someone else has had this problem.
  • Back

    Have been out for a couple of months with a back problem and subsequent operation but am getting back into things now. There was a useful webcast whilst I was off showing the power of the dataview web part:

    http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032256050&EventCategory=5&culture=en-US&CountryCode=US

    which had a couple of really useful things in. Maybe I am being blind but I can't see how you can rerun this webcast from this page...

    One thing was passing parameters through to the dataview which I think is also covered in someone else's blog and there are details of this here:

    http://support.microsoft.com/?id=831093

    I've now used this a couple of times and it's really cool - for example if you want to pass 2 dates through to a calendar and only show the entries between those two dates.

  • Superstitious

    I have now been off work for 5 weeks but have been trying to keep in touch with what is going on in the Sharepoint world!

    Now I just have to stop being superstitious as all is happening on Friday 13th - I have an appontment with the consultant finally and my house sale should be completed on that day - it could all go horribly wrong!!

  • Site Definitions - adding navigation

    I am tring to create a new site definition but I want to include a custom navigation bar in there and I am not sure how to do that. I'll have a look around and see if I can come up with any answers.

    26 July
    OK, so it is easy enough to just add another navbar to the onet.xml which creates OKish with the site but if you change the navbar then the changes only take effect if you make a real change to that page and so for it to take effect on every page you have to make a change to every page and obviously this is not practical.

  • Annoying thing in conditional formatting

    I have been using conditional formatting in my web part pages but have been a bit annoyed at some of it - for example, I want to display a field only when it has some data in it so I set the conditional formatting to hide the field if the field Equals blank. However, it translates this as the field being null which as we know is not the same, as it is only null if the field has been added after the item has been created - if you save an item with an empty field then it still shows. So, I have had to change my conditional formating to show the field if the field is greater than 1, which I assume to be the lowest thing it can be.
  • Loads of Stuff!

    There seems to be loads of new stuff on the internet about web parts etc - it's just a question of finding the time to test all of these things out. One thing I must try and look at is integrating Reporting Services with web parts: http://www.gotdotnet.com/community/workspaces/workspace.aspx?ID=176E78A1-4D90-4860-9BD8-DA93DFFA8FD1 as i have heard great things about RS.
  • What's New

    Have just downloaded the What's New web part from Lead-It and this seems to work well, code is here: http://weblogs.asp.net/jan/archive/2004/03/04/84011.aspx Will implement this in our production servers later...
  • Change to edit/disp dropdown

    Someone in SharepointU gave some really cool code to change/add items to the edit dropdown. I have been using this but have come across a couple of issues:

    Firstly, I created a Print drop-down which went to my newly created printform.aspx, however, I subsequently found that smigrate would only move the standard edit, disp and new forms and would break any others.

    Secondly, where I had more than one list in a web part page and I wanted each one to go to its own form, It would only refer to one of the content editor pages so I needed to know the code to specify that and I finally found it - it is:

     var strAction = "document.location.href='" + ctx.editFormUrl + "?xStatus=Published&ID=" + currentItemID + "'"; 
     
    (this is to go to the editform....)


Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts