Archive for March, 2006

Insert a Sharepoint list item from web services

I recently wanted to use Sharepoint’s web services to manipulate a list on one of our WSS sites.  I wanted to submit a list item from a remote location, so using the Lists web service (http://<server-url>/_vti_bin/lists.asmx) seemed to make sense.

There are many examples of inserting a list item in Sharepoint using the web services out there on google, and they are helpful.  They tell you how the Lists api works, because its not really intuitive, as the argument to the web service is an XmlNode object.  Basically, what you submit to the web service is a xml document that contains the values for the list fields that you want to add, something like this (lifted and modified from here):

string sBatch = string.Empty;
sBatch = “<Method ID=\”1\” Cmd=\”New\”>”;
sBatch += “<Field Name=\”ID\”>New</Field>”;
sBatch += “<Field Name=\”Title\”>My Title</Field>”;
sBatch += “<Field Name=\”EventDate\”>” + DateTime.Now + “</Field>”;
sBatch += “</Method>”;

This is one way to construct the xml document that you need to submit. This xml will add an item with a title of “My Title” and an Event Date of the current date/time.  This code works, theres nothing wrong with it.  Its just that this is the extent of the examples out there, I couldn’t find anything that was more complex, for instance, an example of inserting an item into a Sharepoint list where one of the fields in the list is a lookup to another Sharepoint list.

Consider a list where there is a Status column, which is a lookup to another list that has possible values of “Submitted”, “Approved”, “Rejected”, and “Completed”.  How do you specify the value for this field? I initially tried simply inserting the text value of what I wanted, so my xml would look like this:

<Method ID=”1″ Cmd=”New”>
     <Field Name=”ID”>New</Field>
     <Field Name=”Title”>My Title</Field>
     <Field Name=”EventDate”>3/25/2006 12:00 PM</Field>
     <Field Name=”Status”>Submitted</Field>
</Method>

But this doesn’t work.  After some more trial and error, I tried the index of the value that I wanted, in this case 0, because “Submitted” is the first item in the list, and presto! My item was inserted, all was good.  The downside that I see to this, is that if the indices of the items change, you have to change your xml. You could get around this by querying the lookup list and finding the index of the item dynamically each time, its your call.  So if you want to insert an item into Sharepoint with a field that is a lookup field, here is an example of what your xml should look like:

<Method ID=”1″ Cmd=”New”>
     <Field Name=”ID”>New</Field>
     <Field Name=”Title”>My Title</Field>
     <Field Name=”EventDate”>3/25/2006 12:00 PM</Field>
     <Field Name=”Status” Type=”Lookup”>0</Field>
</Method>

I hope this helps someone else who is scouring google for help :)

UPDATE: I forgot an important piece to the resulting xml. You need to include the Type attribute on the Field element, I have added it to the xml above in red, my apologies.

Looking for projects

I’ve been looking for a new project to work on outside of work for awhile now.  I’ve had some ideas, but they have been getting nixed for a variety of reasons, lack of interest on my part certainly being one of them.  I’m considering devoting some time to an open source projet, so myabe I’ll have a look around and see what interests me.  Theres no shortage of .net projects on sourceforge, so I should be able to find something that catches my fancy.

Been in kind of a blogging rut lately as well, so maybe this will inspire some more posts as well :)

If you know of any cool projects out there, don’t hesitate to let me know, thanks!

(As an aside, I only missed 5 games in the 1st round of the NCAA tournament (Iowa, Kansas, San Diego St., Marquette, Wisconsin) leaving me in first place after round 1)

Is your first agile project doomed?

People don’t generally get things right the first time. Remember the first time you tried to ride a bike, or the first time you drove a car? Chances are you fell off, or had a fender bender.  With this in mind, doesn’t it stand to reason that the first time you try to use some agile methods in your software projects, you’re going to get them wrong?

The problem is that when you fall off your bike, its not a big deal.  Screwing up a software project can cost big bucks though.  How many chances do you get to figure it out? Do you spend a bunch of money up front to get some agile consultants and training so that you can ensure you’re doing it right?  Doesn’t it also depend on everyone buying into the processes and methodologies?  If you have some developers who think agile is a bunch of hooey, I would think you’re screwed from the get-go.

I suppose this argument could be applied to anything, but agile in particular seems like a big step and one that requires a lot of discipline to follow procedures and trust the people around you.  What do you think, is your first agile project doomed?

More Origami

Ah, finally, some sensibility about the Origami hype:

There’s no way this thing is going to be able to meet the expectations of the hype being placed on it.”

And from the last place I would expect it.

Firing javascript events when textbox changes

Just a little heads up to anyone putting client code on a textbox.  If you want some  javascript to run when the text in a textbox changes, use OnKeyUp instead of the intuitive OnChange event.  OnChange will only fire after the textbox has lost focus, rather than as the keys are pressed in the textbox, whereas OnKeyUp will fire when, well, when a key comes up!

Of course, if you only want your code to run when the textbox loses focus anyways, then continue using OnChange :)