Archive for the ‘SharePoint’ Category

Java code snippet to export Lotus Notes Documents to XML

Wednesday, 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

Thursday, 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

Thursday, 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

Thursday, 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.

SharePoint Lookup Type

Friday, 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.

Reseeding SharePoint ID field

Thursday, 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

Friday, 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

SharePoint Sequence Number - [ID]

Tuesday, February 23rd, 2010

I am developing software that uses SharePoint Web Services (UpdateListItems) to add or bulk load items into a list from a Lotus Notes extract. More on this later when I finish. Sequence numbers are not one up numbers from the last item (last item + 1). Instead they are true sequence number, similar to Oracle and Sybase. I found this out by bulk loading a few items then deleting them and reloading. So, if you are starting from a scratch list or a list that you have not loaded/deleted any items from, then this is not big deal. However, if you have loaded/deleted items, then the numbers will be out of sequence.

As far as I can tell, there is no sequence number reset. Too bad.