[Looking for Charlie's main web site?]

Integrating ColdFusion and the REST API for Harvest (TimeSheet Service); Accessing XML in CF

Often we will find API docs for a given service without any reference to a CFML example. I just experienced that, and while I offered a suggested example to the vendor, I wanted to share it here in case it never gets posted. At least if someone Googles in the future they may find this. Also, I conclude with some insights into learning more about the power of XML processing in CF.

I'll demonstrate here calling the REST API for the Harvest online timesheet application. (If you would want to point me to another alternative timesheet app, no need as I'm happy. I realize there are many. Indeed, I list many of them on my CF411 site section for time tracking tools and services.)

Anyway, the Harvest API docs pages do show a Ruby example. While I didn't take the time replicate that exactly (it has a few more touches like error-handling, extensibility, etc), I did want to at least show how one could call the REST-based API using CFHTTP.

Some Simple CFHTTP Examples

Here are two simple examples, first, showing calling the who_am_i method:

<cfhttp url="http://subdomain.harvestapp.com/account/who_am_i" username="user@email.com" password="password">
   <cfhttpparam type="header" name="Accept" value="application/xml">
   <cfhttpparam type="header" name="Content-Type" value="application/xml">
</cfhttp>

Note that I'm using the same nomenclature they do in their docs, in that you would need to change the "subdomain" value to be whatever your own it. Also, like them I've just left the placeholders above for your Harvest username/password. And the API docs show needing to pass in those two headers, which I do in the CFHTTPPARAM.

Getting TimeSheet Entries

The next, more interesting example calls the method to get the timesheet data for a given day (and yes, since the REST API has no state you do need to pass in the username/password on each call. In a more complete app, you might prompt the user for those and store it in a session for reuse, etc.):

<cfhttp url="http://subdomain.harvestapp.com/account/daily/245/2009" username="user@email.com" password="password">
   <cfhttpparam type="header" name="Accept" value="application/xml">
   <cfhttpparam type="header" name="Content-Type" value="application/xml">
</cfhttp>

Note also that the date is in Julian format (the number of the day in the year). I'm showing Dec 10. Again, I could elaborate this to take in URL variables to change the date. I'll leave that to the reader.

So how do you calculate the date in Julian format? Well, you could of course modify the code to use CF's date/time functions to do a conversion, but if you just want to look up a given day for manually, here's a trick. If you've never noticed it (as a Harvest user), the real web-based Harvest timesheet always also shows the julian date in the URL for a timesheet entry.

Getting Real Data from the Returned XML

The result of both calls is some XML. In the first example, I ignored it. In the second, of course, you need to get the data.

So I pass it to the XMLParse function (new in CF6) and still missed by many. That converts the XML into an internal CF XML object, which represents the XML as a series of nested structures, arrays, and attributes. If you do a CFDUMP of the result, you'll see what I mean:

<cfset result=xmlparse(cfhttp.filecontent)>
<cfdump var="#result.daily.day_entries#">

And to output the hours for the first entry, one could do this:

<cfoutput>Hours:#result.daily.day_entries.day_entry[1]["hours"].xmltext#</cfoutput>

How did I figure out that nested set of arrays and structures, you ask?...

Learning More about XML processing in CFML

I won't elaborate here about how to go about accessing the various parts of the (sometimes complex) internal XML object. But you can learn it really quickly. Most CFers are blithely unaware of the power of this feature set (or they get confused and give up). There are two (well, three) places you can learn more.

First, the best resource on CF/XML processing (in my opinion) is a great extended Adobe Devnet article by Nate Weiss. Though from 2002, it's an all-time classic (recovered from the archive.org site).

He introduces the topic assuming you know nothing about XML, and steps quickly into processing it in CFML (reading and writing it), including understanding all those structures, arrays, and attributes. Within just a few pages, you'll be amazed at how much more productive you can be with XML processing in CFML.

Nate even introduced the valuable concepts of using XPath/XMLSearch to make accessing XML even easier and XSLT to do conversions from XML to other formats. He does all this very gently and in a compelling way. I still refer people to it often, to this day (and return to it myself when I'm stumped).

That said, there are of course a few ways that XML processing in CFML has evolved since CF6, so you will want to check out the CF docs as well. Besides the CFML Reference on XMLParse, note that there is also a chapter on the topic in the oft-missed ColdFusion Developer's Guide.

Many only know of the CFML Reference, but they miss out on this 1,000+ page free online book (from Adobe). The CF8 version of this is here and the chapter here. The CF9 version of the manual is here and the chapter is here.

Hope any of that may help someone.

Running a Google Group? Don't leave it open to spamming

Do you run a Google Group (or belong to one) that's suffering spam? Here's how to stop it.

I belong to (and also run) many Google groups, which can offer a great solution for a hosted mailing list. Sadly, if the group owners aren't careful, the list can soonbecome a haven for spam.

But there are three simple solutions (one in particular) that the group manager can take to prevent the problem, and I am NOT talking about moderating every message. Two of them add only a little new effort for you as manager, but the reward is so worth it.

To make (or consider) the changes, visit the page to manage settings at http://groups.google.com/group/groupname/manage_access. Or to get there, select "group settings" on the right, then choose the "access" tab at the top, and make the changes below, which I discuss after the screenshot.

From there, change 3 settings:

  • "who can join" - change from "anyone" to "people can request an invitation to join". You don't need to use the "custom question" option. This will just require that people request you let them in. Again, most spammers won't bother. It's like how locking your car door causes most thieves to just move on. More than that, this changes it so that people can't just join by sending an email, which really is where most spam comes from
  • "Who can post messages?" - change from "anyone" to "members only"
  • "Message moderation" - you don't need to set it to "all messages are held for moderation. Leave it as "No moderation", but do consider checking "Messages from new members are moderated". Yes, it means that when a new member posts a message, you'll get an email with a link to view their message and mark them as either "always allow" or "block".

Doing these, especially the first, really will stop most of the spam. Your members will really appreciate it.

cf.Objective() 2010 call for speakers, ends Nov 30

It's funny, no sooner had I posted my entry yesterday about CFUnited's call for speakers, then I started seeing the tweets about cf.Objective() 2010 also having its call for speakers. Had I noticed sooner, I would have covered them both at once. Oh well.

A big difference is cf.Objective()'s is ending November 30. Check out Sean Corfield's post for more information on the cf.Objective() call.

CFUnited "call for speakers" open until mid-January

Sometimes people say, "I never knew there was a call for speakers" for a conference, so the folks from CFUnited as asking that the word be spread that the call for speakers is open until mid-January.

Here are the tentative tracks for sessions:

  • AIR and UI Development - How to enhance the experience of your applications. Bring your application to the desktop or mobile.
  • Best Practices - Tips and Tools for improving and protecting your website.
  • ColdFusion (advanced) - Building applications, Charting, APIs, Custom Tags, PDF, Forms, Railo, Groovy, Facebook apps, Geolocation, Web-Oriented languages, and Integration.
  • ColdFusion (basics) - Getting started with ColdFusion
  • ColdFusion 9 and ColdFusion Builder - Topics from Adobe related to the new release of ColdFusion 9 and ColdFusion Builder
  • Configuration,Testing & Deployment - Deploy your websites with minimal issues and know what to expect
  • Databases - SQL, reporting, procedures, integration, server tuning
  • Flex (advanced) - An indepth look at building Flex applications
  • Flex (basics) - Getting started with Flex
  • Frameworks - Discover various Frameworks for ColdFusion and Flex
  • Managing Projects - Team Management, Project Requirements, Customer relations, Project management
  • OO Development - Object Oriented programming and using CFCs

They note as well that they're always open to new speakers.

Finally, the pointed out as well that the early bird deadline is Nov 30. More at CFUnited.com.

I've made it onto the CF9 video interviews at Adobe.com

Someone told me today they'd spotted me on the CF9 video interviews offered on the Adobe site. Pretty cool. There are actually a couple of sets of video interviews that I made it into.

One is a 3-minute conglomeration of comments from several people. These are both the "official" Adobe talkinghead-style videos, and some are more like "live remote shots" taken from the floor of CFUnited. Besides a couple of appearances in it, near the end they included me saying something fairly quotable. I'll let you find it. :-)

Then there's a another set of individual interviews with different folks (the talking head style), which appear (currently) at the top of the CF9 product page. You click on whichever one shows up (or click "community feedback") and an interface like slide show picker appears. You can pick any of them and at the end it offers to advance to the next. (That link to them at the top may eventually no longer appear on that page, I suppose.)

It was a treat being interviewed for these.

About the process

I got the invite over the summer and was told they'd be taken in a room at CFUnited. I assume the others were done there, too, but I don't know. The room was staffed by a video production team.

There was no way of telling for sure as we did them whether what we said would be included ultimately, and/or how much. Indeed, the interviews were a lot longer than what was showed (about 30 minutes for less than a couple), so much ended up on the cutting room floor for each of us, obviously. That was to be expected, of course, and I'm just thrilled to have been included at all.

Any disappointments?

My only disappointment: well, if you look at the videos and even the pictures at the top of the page, you'll notice something about mine stands out from the others. The production folks had made a point from the start about wanting me to "be sure to use my hands", so my inteview and picture show me gesticulating pretty vigorously. :-) It's not really my normal style, but if that's what they wanted.

But then I notice NO ONE ELSE is. Maybe I was an early interview and they dropped it eventually. If I knew the folks doing the interviews, I might feel like they punked me. :-) Heck, even on the tight shots (where they zoom in the editing) you can still see my fingers flying into the frame. Grr... :-)

And yet another appearance spotted

I notice that my shiny face also appears (for now) further down the product page next to a link labeled "Get Inspired". That's cool to see. I suppose it may well rotate with other folks (but it hasn't when I've refreshed it today).

Guess my 12 years of CF experience have born yet more fruit. Thanks, Adobe. And certainly I hope what I said is of value to some viewers, brief though the interviews are. Next time, if invited back, I'll also wear a less floppy-looking shirt! :-)

Palm owners: how to solve the "failed to backup" error for PmTraceDatabase on hotsync

If you're a Palm device owner who has been annoyed that attempts to hotsync your device fail with "Hotsync session completed with errors", because it "Failed to backup 1 file", the PmTraceDatabase, I have a solution for you, from Palm.

The problem is annoying, because if you have no other sync failures (such as Outlook calendar sync errors), you can't know for sure without digging into the hotsync log.

The good news is that Palm has come out with a solution to make this finally go away:

Update: Curiously, that link I had originally offered here in 2009 goes to a page that no longer offers or explains the fixpmtrace.prc file, as it used to. That's odd.

And while I found another version of the page on the site: http://kb.hpwebos.com/wps/portal/kb/na/centro/centro/bell/solutions/article/44937_en.html. Sadly, though, even that page has a failing link to that prc file.

I found all this in answering a question someone raised as a comment.

For more details, and a possible alternative solution, see my reply comment at http://www.carehart.org/blog/client/index.cfm/2009/9/7/solving_palm_pmtracedatabase_problem#c885AB116-E50B-DEA9-80CFFE5C48A7121E.

http://kb.palm.com/wps/portal/kb/common/article/44937_en.html

As the Palm site page discusses, you install that app onto your phone, and then run the FixPMTrace app on your device. It's important to note that it's NOT ENOUGH just to install the app onto your device. You do have to run that app from the Palm launcher (the list of apps, accessed by the "home" key, as usual) in order to have it do its magic. All it does is turn off the archive bit on a file so it stops trying to back it up.

Hope that helps someone else.

PS And before some of you jump on me for still using a Palm, :-) just know that yes I am seriously considering moving to an iPhone after several years of relative happiness with my Palm devices. I've been using a iPod Touch for a couple of years and really like that. Carrying both devices is of course a pain, so reducing it to one just makes sense.

And yes, I know about the Palm Pre. It's just that Sprint coverage in my home is really poor, and since I generally work from home, I just can't take it anymore. The Pre won't solve that (I called: they said it wouldn't likely be any better.) Since my wife has ATT and she's been happy, the forced move to ATT with the iPhone isn't a problem.

Still, I leave this Palm tip for those who may benefit.

Interesting "Test Focus Guide" for SP2 of Windows Server 2008/Vista

If you're running Windows Server 2008 or Vista, you've probably heard by now that there's a new SP2 release (or learn more here.)

One interesting document you might miss is the "Windows Vista SP2 and Windows Server 2008 SP2 Test Focus Guide", which is a 40-page guide that lists various changes, with scenarios and step-by-step instructions to recreate and observe the feature changes.

That's a nifty idea, and one I wish more vendors offered. It's not something I've seen offered for previous Windows OS releases (base or SP's).

I don't think it lists every feature, but it does list many that I'd not seen mentioned in the more glitzy "what's new" docs (at the URL offered up top here). By contrast, the Test Focus Guide is more text-heavy (all stuff, no fluff) and kind of rough.

For instance, I wish it offered more of a table of contents, because you can't readily eyeball what all it covers. I found the easiest way to find each topic is to search for "goal:", since each scenario has a listed goal.

Anyway, check it out. You may find something of interest there among its dozens and dozens of scenarios.

Finding the forums for the new Adobe Presentations

Just want to share this bit of info, in case others find it as hard to locate as I did.

If you start to use the new Adobe Presentations service, an online presentation-building tool, now at labs.adobe.com, you may want to engage in some discussion with other users, so may go looking for some forums. You may struggle as I did.

Sadly, there's none for it listed at the acrobat.com forums page. Perhaps that's because Presentations is still in lab status.

There's also none listed in the Help menu for Presentations. There is a link to share feedback, which gives you an email address. That's better than nothing, but it's not a discussion forum. Some may even fear using it if it might be a black hole.

I decided to go ahead use that feedback address. I was delighted to get a response pretty quickly (well, first an automated one, and then a real person).

But what surprised me most was that the automated email (offered in response to using that feedback address) offered the URL for the forum!

So where is the forum? It's at: http://forums.adobe.com/community/labs/presentations/.

I responded that this link really ought to be listed in the Help menu of Presentations, but that suggestion seems to be challenge for them to implement. Oh well. I decided to share the info here, and also as a comment in a blog entry on Presentations in the Acrobat.com blogs.

Just seems it shouldn't be so hard to find these forums.

Several useful web dev topics, "Better Explained"

I happened upon a site today with many quick, to the point, highly graphical articles introducing web app development topics that may interest some of my readers. Wanted to pass them along:

A few focus on Javascript and/or site building:

Still others aren't specific to web development, but can be valuable to all kinds of developers, and it was one of these that led me to the site in the first place:

The site is Better Explained, whose tag line is "Explanations for everyone". The author does a pretty good job of that. Some of the topics are a little too one-sided (the discussion of HTTP compression does only show setting it up in Apache, not IIS), and of course there's no mention of CF anywhere. :-) But we can't expect that from everyone. There are lots of positive comments and linkbacks on on many of the entries, so he'd done a good job in the eyes of most.

Indeed, if you may be hearing the siren call of Ruby on Rails, they have an article on that: Starting Ruby on Rails: What I Wish I Knew. There's also an intro to MVC, but again it's from a Rails perspective: Intermediate Rails: Understanding Models, Views and Controllers.

If there's something you'd like to see the author address on the site, he has a post for that, too: What do you want Better Explained?.

Setting Google to Show You More Results Per Page: how and why

In a recent entry, I made mention of the fact that I have Google set to show me 30 results per page, rather than the default of 10.

Some may read this and say, "big deal, I've been doing that for years", but it's one of those little things that some just never notice or think of. If you've not considered the option, why not check it out?

(Update on 9/30/2010: Others may have noticed that they DID have it set to more than 10, but recently they lost that functionality. I have the solution for that, as well.)

Others may say, "well, why choose to see more than 10? They offer buttons to let you page through the results", but the point is that people often will not page through them. I can tell you from my own experience that seeing more than just those "top 10" results when searching makes me more inclined to quickly consider more results. More on why do it in a moment.

How to make the change

The change it really simple. Just click the "Search Settings" box to the right of the top of the search page at google.com. (It used to appear to the right of the search box as a "preferences" link, but now it appears at the top right instead.)

If you're logged in, it will instead show as a link to "Settings", with "Search Settings" as a menu option under that when you click on it.)

On the preferences page, the 4th option controls the number of results.

Sure, they warn that 10 results per pages is "faster", but in these days of high speed internet, that's of course a relative assertion.

Update on 9/30/2010: Need to turn off Google Instant search

As I noted above, some may have noticed that even with that setting set, and saved, they still see only 10 results. In fact, if you re-open the preferences page, you'll see that it just ignored your choice and is back to 10. What gives?

The problem is the new "Google Instant" search feature, implemented recently (by default), which allows search results to appear as you type in your search criteria. If that's enabled, then Google does not let you set the results to more than 10. That's a shame, but worse is that they don't warn you of this when you try to change the number of search results.

The setting appears two below the "number of search results". Choose "Do not use Google Instant", if you want to see more than 10 search results.

Sadly, if you try to change both settings at once (turn off "Google Instant" and change "number of results"), that doesn't work either for the same reason above. Instead, do it in 2 steps: turn off Google Instant, save the preferences, then edit them again and change the number of results, and save that.

It really is too bad that Google doesn't handle both problems more gracefully.

Why to make the change to see more results

So why make the change to see more results? We all tend not to want to page forward through search results, right? But often some of the best results--those with real valuable info--are beyond the top 10, perhaps just beyond them, or perhaps 30 or 40 down.

Of course, hucksters know that people are reluctant to page down and go to great lengths to get their stuff in the top 10. (Granted, there are many fine entries which also show up in the top 10 just because they deserve to.)

But if you set your results to 30 at a time (or some other number larger than 10), you're just more likely to find (or consider) other results. It's surely paid off for me, and the speed to show more results is hardly noticeable.

Also, seeing 30 at a time makes it feel like no problem to go through a hundred results (including following the link to look at some of them) in a matter of minutes. Just something psychological about feeling that paging forward a couple of times is no big deal, but I see a lot more results doing that than if it was set to 10.

(And given the conflict with "Google Instant" discussed above, I'm happy to forego that feature to see more results instead.)

Hope this may help some of my readers.

PS Oh, and if you have changed the Google preferences but find your browser keeps losing the changes over time, check out the other recent entry I referenced at the top here, which addresses this very problem.

More Entries

BlogCFC was created by Raymond Camden. This blog is running version 5.005.

Managed Hosting Services provided by
Managed Dedicated Hosting