Cascading Lookups - Another approach

May 11th, 2010

I have 3 dropdowns. In the last few days, the middle one was populated with more than 19 items. As you know from previous posts, the 20th item triggers IE (only) to change the control type. Before, my 3rd dropdown contained more than 19 items, but I didn’t care because it did not cascade. But, now that the middle dropdown has changed type, I ran into problems. The problem is that I could not get the on-change event to behave properly. The event fires when you tab off the control, so I had a hard time figuring out what the current value was for the cascading control.

So, to make a very long story short, I changed the three dropdowns fields to edit fields. And, in Designer, I added 3 unlinked dropdowns controls. I changed my javascript to cascade the unlinked dropdowns and everything worked.

I had to make sure I moved values from the unlinked controls to the edit fields, but other than that, it was easy.

This is the best solution so far. Stay tuned though.

Java code snippet to export Lotus Notes Documents to XML

April 21st, 2010

View view = db.getView(”myview”);
Document doc = view.getFirstDocument();
while (doc != null) {
BufferedWriter bw = new BufferedWriter(new FileWriter(”c:\temp” + File.separator + doc.getUniversalID() + “.xml”));
doc.generateXML(bw);
bw.close();
doc = view.getNextDocument(doc);
}

——————————————————

If you have any questions, please send me an email at Randy@CSATechConsulting.com

Site Banner: wrap anchor around logo image w/ jQuery

April 8th, 2010

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js”></script>

<script>

$(document).ready(function(){

$(”#ct100_PlaceHolderGlobalNavigation_CustomSiteBanner_LogoCol img”).each(function(){

var a = $(”<a/>”).attr(”href”,”http://mydomain.com/index.html”);

$(this).wrap(a);

$(this).css(”border”,”none”);

});

})

</script>

Adding ‘clickable’ images to Custom Site Banner

April 8th, 2010

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js”></script>

<script>

$(document).ready(function(){
$(document.createElement(’img’))
.attr({src:”http://mydomain/images/Logo1.png”, title: “Click here to go to mydomain1″})
.addClass(”icon”)
.appendTo(ct100_PlaceHolderGlobalNavigation_customSiteBanner_LogoCol)
.click(function(){document.location.href=”http://mydomain1.com/default.aspx”;})

$(document.createElement(”img”)
.attr({src:”http://mydomain/images/Logo2.png”, title: “Click here to go to mydomain2 “, style:”position:relative; left: 70px”})
.addClass(”icon”)
.appendTo(ct100_PlaceHolderGlobalNavigation_customSiteBanner_LogoCol)
.click(function(){document.location.href=”http://mydomain2.com/default.aspx”;})

$(document.createElement(”img”))
.attr({src:”http://mydomain/images/Logo3.png”, title: “Click here to go to mydomain3 “, style:”position:relative; left: 90px”})
.addClass(”icon”)
.appendTo(ct100_PlaceHolderGlobalNavigation_customSiteBanner_LogoCol)
.click(function(){document.location.href=”http://mydomain3.com/default.aspx”;})

})

</script>

SharePoint Lookup: a different approach

April 1st, 2010

It took me several days to get this to work, but in the end it was worth it. To recap, when a lookup list contains more than 20 items, IE renders the control as an input control that behaves like a SharePoint choice type. The control allows type ahead capability, which is probably why MS did it that way, but the control is very different than a dropdown. In a dropdown, all you have to do to cascade is to rebuild the select/options. So, every time dropdown #1 changes, I rebuild dropdown #2 select/option. I am using SP Web Services to read the dropdown #2 list using dropdown #1 selected item value.

The choice type makes it difficult but not impossible to cascade lookup values. You just have to use another approach. My approach was stop fighting SP and deal with the choice type. I did two things: 1) determine if the control has changed to input/choice, 2) build/rebuild the choice items (control.choices) for the control using the list item values.

This worked as designed and I deployed this it this morning. Glory be. Now, I can move onto something new, although I learned a great deal from this experience.

When time permits, I will post the code, although it is very complicated removing anything from work.

Extracting Lotus Notes Data and Importing to SharePoint List.

March 26th, 2010

Step 1: export Lotus Notes database to XML. You can either write a Notes agent or write a java program that does it. I did the latter. The export extracts all fields including rich text, attachment, doc link, embedded image, etc. The attachments and embedded images are encoded in base64.

My first attempt at this was to write an extract in Java, but as I learned later it is much easier handling XML. Plus I had written several parsers before. Keep in mind that everything is extracted, so before extracting a database w/ many document w/ many LARGE attachments you may want to allocated additional time for the effort.

Step 2: Import to SharePoint List: Here is my technique. write java program that parses the extracted XML documents and build javascript/html file that calls SharePoint web services to insert items into the List. Then I import the html file to a document library. The java program builds a button that when clicked runs the javascript that insert items into the list. All the variables such as database name, server name, list name are read from a properties file stored locally.

The program also extracts all Notes attachments. Attachments are actually in the XML file and stored in base64 format. The program builds javascript/ajax code that calls add attachment web service for a given item.

This has been a big hit because the java programs runs outside Notes and extract user defined fields and runtime variables are driven by the property file.

This technique does not use .NET at all. Good thing because I do not know much about it. It is very simple and works for every database, both local and server based.

SharePoint Lookup Type

March 26th, 2010

The bad news is that it took me 7 hours to figure it out. The good news is that I figured it out.

When you define a column in a SharePoint list as type = “Lookup”, and if the list that you are looking up contains more than 20 items, SP renders the dropdown controls as combo box controls. SP also changes the control names. Even worse - if you can believe it - SP changes the behavior of the controls. All this in toto throws my “cascading lookup” software faster than a tsuri komi goshi. Very forbidden.

To add insult to injury, the combo box control is much different than the dropdown control which my software complained bitterly about. For some unknown reason, SP renders combo box code similar to choice controls. Unfortunately, the choice control does not contain select/option tags that my software has its way with. Also very forbidden.

What really “threw” me was that one of my lookups did not morph into a combo box while the others did. Call me simple minded, but it did not occur to me - I would argue it would not occur to any sane individual - that the item count had anything to do with the morphing. I will not bore you with the gory details and the pain and agony I suffered to figure this beast out, but suffice to say that I reached deep into my bag of tricks and came up as empty as the Red Bull that I just polished off.

Bottom line is that I know what is wrong, but I certainly can’t fix it as only Microsoft can undo their dirty work. Overwriting the controls is an option I suppose but it requires .NET ninja powers that I do not have. The “keep the lookup lists below 20 items” solution is not a viable option.

I am relatively new to SharePoint and Microsoft non-office products. How Microsoft can get away with such egregious “bugs” in their software is beyond comprehension. Coming from the stable, tried-and-true, tranquil, happy-go-lucky and carefree world of Java, J2EE, JSPs and Servlets; this new world is unfamiliar and somewhat unsettling.

Additional Info

Update:
3/29/2010: tried to out smart SharePoint today. I created an empty list with a title field that I used as a lookup list. My thinking was that if I point my three lookup columns to the empty list I would not experience the control changing when the item count > 20. Well, it worked great until I saved the item. The error was the standard, “SharePoint has an error”. Oh well, it was a noble effort, unfortunately it did not work. I still don’t understand why. I suppose the column value must be in the lookup list. I tried to trick the beast and I failed. Onward.
3/28/2010: just read a post that states that FF renders the control as select (good - my software likes select) and IE renders to “choice like” control (forbidden). IE is the bad guy. Now, why does that not surprise me?  Not sure why they are rendered differently. Unfortunately, in our shop we MUST use IE.

What I like about jQuery so far.

March 15th, 2010

As everybody know, SharePoint controls are difficult to work with. One advantage is jQuery allows you to easily work with the DOM and manipulate controls and styles. I am beefing up on the technology, so I bought a book, “jQuery: Novice to Ninja”. I do not recommend it.

Today, I used jQuery to build cascading drop down software because some yo-yo bought the wrong Bamboo web part (Lookup Selector). It took me about 1 hour! Easy peasy.

I am taking SharePoint .net programming next week at Learning Tree.

More info http://blogs.technet.com/vedant/archive/2009/02/08/jquery-and-sharepoint-2007.aspx

Reseeding SharePoint ID field

March 4th, 2010

I was desperate, so I tried to delete items from the trash bin, thinking the seed value would re-set. No such luck. The UpdateListItems service ID starts from the last item ID +1.

SharePoint Column Names

February 26th, 2010

For example: Column name “Upload Comment” is actually stored as “Upload_x0020_Comment”. I actually knew this from looking at code in SharePoint Designer, but it never occurred to me that this caused  my UpdateListItems (Cmd=’New’) web service to fail. It failed by not inserting the item, not by flashing “Error Will Robinson” messages at me. So, I replaced spaces in column names with “_x0020_”, and it worked. The java code to do this is: replaceAll(” “,”_x0020_”);

So instead of:  <Field Name = “Upload Comment>A Comment</Field>

I used this: <Field Name = “Upload_x0020_Comment>A Comment</Field>

I am using a java program to build javascript that invokes the UpdateListItems web service. The datasource is Lotus Notes. At this point, you must copy the javascript into a content editor web part. The script builds the javascript including a button. Clicking the button makes the magic happen. More on this later.

Good article concerning this is at http://httpcode.com/blogs/CommentView,guid,fb4a2a24-c1e7-4f23-9317-5ae7f1430036.aspx