Tag Archive: Lotus Notes

Need Some Hack-tastic Help

So I’ve got a problem. Apparently I am not the only one with this problem, nor is it a new problem. That being the case, I wondered if anyone had a more elegant (aka less hackish) solution.

I’ve got a scheduled agent using LotusScript, specifically using the “ComputeWithForm” method to (hopefully) recalculate computed fields. I could swear that this agent used to work, and now does not. Coincidentally, someone recently pinged me to see if something was up with 8.5.2 because he noticed the same behavior (that is used to recalculate and now does not) once he upgraded. A little bit of digging, and a lot of bothering people (thanks Julian!) discovered this blog post from Duffbert (whom I would have bothered, if he wasn’t on vacation!) showing that this is an iffy proposition and has been since at least 2004!

Two workarounds are stated, the first being ToolsRefreshAllDocs, which unfortunately, does not work for me in this case since I get an error about too many documents.

The second workaround is to have the LotusScript agent perform the calculation itself (rather than refreshing the field calculation on the document).

I think both of these sound pretty hack-tastic.

All the other solutions I can come up with are front-end/UI methods and therefore won’t work in a scheduled agent. I supposed I could write a front-end agent and just wake up every morning at 3AM to run it manually.

Anyone else out there run into this? Have a better solution?

Transform Yourself or At Least Your Code

I think @Formula is a frequently forgotten art of Lotus development. Many people start out learning @Formula, then move on to LotusScript and don’t look back. That can be a mistake as @Formula can sometimes be more efficient than LotusScript. There are @functions that just don’t exist in LotusScript, or require fewer lines of code, or take more parameters.

Today I bring you @Transform. @Transform can be used to transform a value, or even better, a list of values. Take for example a list of user-entered values. The values were supposed to be in percentages. Some users entered “50″ meaning 50% and others entered “0.50″ also meaning 50%. How can we take the list of values and only change those that were in the incorrect format? @Transform, of course!

We’d like to show all of our values in decimal format, so all we need to do is use the following code:

@Transform (valueList; “x”; @If (x>1; x/100; x) )

This translates into: for each value in “valueList”, which we will call “x”, if that value is greater than 1, then divide it by 100, otherwise, leave it as is.

Another example is my running log. Say we would like to transform all the values in a list of running times from minutes to seconds. But again, we are concerned that some users may have already entered the data in seconds. TRANSFORM! (Picture me like Harry Potter with my wand when you read that).

@Transform (valueList; “x”; @If (x<60; x*60; x) )

This formula assumes that if the user entered a value greater than 60 then they must have entered the value in seconds, not minutes.

As with many @Functions, you are only limited by your imagination and creativity in coming up with ways to utilize the formula. Any formula can be used as the third parameter in @Transform, including @Nothing:

@Transform (valueList; “x”; @If (x<60; x*60; @Nothing) )

Similar to the previous examples, but returns nothing for a value if the value does not meet the criteria, effectively removing the value from the list.

Happy Transforming!

Use The Tools – Part 2

A couple of weeks ago I blogged Use The Tools, about using tools to help you. Yes, you could do it the hard way, but why? Last time I wrote about Noteman. Today I want to mention Stephan Wissel’s DXL Magic. I wrote about it way back in May 2009. I happened to need it again yesterday and luckily I checked OpenNTF to see if there was an updated version. Guess what? There is! And it’s super easy to use! Lots of options, easy to use interface.

In my particular instance, I wanted to search through a database to find where particular views were being used. I had reason to believe there were several unused views in the application, but I wanted to be sure I didn’t have some code somewhere that called them. Enter DXLMagic. I simply used the Export button to export the design of the entire application into an XML file. Using XMLPad, I easily searched for the names and aliases of the views. Stephan has added lots of other really cool features in here and it’s FREE! So don’t do more work than you have to! Use the tools!

Here is a screen shot of the Windows version…

DXLMagic.PNG

Use the Tools

I have to remind myself to use tools now and again. Frequently in Domino development, I will slog through and do things the way I know how to do them, whether or not it is the best or most efficient way, simply because it is the comfortable way.

That’s just plain dumb. I admit it.

I maintain an application, like many others it has documents and responses to those documents. Occasionally users need to “re-assign” the responses to a different parent document (and of course, it needs to be done ASAP!). Fine, there is a mechanism within the application to do so. However, life being the way it is, sometimes for reasons too lengthy and boring to get into in this post, the documents needing to be re-assigned don’t get re-assigned.

So, what to do? I could write some code that gets the UNID of the correct parent and replaces the value in the $REF field in the response documents, but I don’t want to do that. And better still, I don’t NEED to do that. There is a TOOL that already does that for me.

Enter Noteman. I received a copy of this to review sometime ago and honestly just didn’t get around to playing with it. The icon is a little Swiss Army Knife looking thing, and I think that is completely appropriate, as it is one of those tools that does a million things. I am lazy and never fully explore it, so am not even aware of all the possibilities. Heck I don’t even know what half of those things are for. BUT, if you take the time and figure out what is there, it can save you a ton of time. Just think how long it would take you to open a bottle of wine without a corkscrew…

Anyway, back to Noteman, which has an “Editor” tool. Right there in the Editor screen is the button “Make Response…”, which does EXACTLY what I needed the other day. I didn’t have to code anything, test it, fix it, re-test it and then update the documents. I opened the parent document in Noteman, SELECTED and COPIED the UNID (can you hear me weeping tears of joy?), then opened the response docs, hit “Make Response…”, put in the new UNID, saved and closed. There is a Multi-Editor tool as well for changing a bunch of docs at once.

It is a cliche, but don’t reinvent the wheel. Use the tools available to you. Save yourself the time and effort that could be spent writing better code!

Multiple Values in a View – Now With More Special

Okay, so in my last (technical) blog post, I noted a problem I had with getting multiple values in a view via LotusScript. I learned and posted that the NotesViewNavigator was the solution.

The wise Nathan Freeman posted a comment, which I think has quite a handy littly tidbit in it, but I fear not enough people read my blog, let alone read the comments on my blog days after a posting, so I am blogging about his comment. With an example and screenshot.

Here is what Nathan said:


“Make a set of documents with several multi-value fields, all text.

Field 1: Red, Green, Blue
Field 2: Me, Myself, I
Field 3: This, That, The Other
Field 4: Apples, Churches, Very Small Rocks

Give them all the same values for Field 1, but randomize the values for fields 2-4

Now create a view that has a column for each of these fields, in order. Set them all to “Show multiple values as separate entries.”

On the first column, turn on categorization.

Now look at your view CLOSELY.

If you want to do something really special, try CreateViewNavigatorFromCategory(“Red”). Then walk the entries and retrieve the .columnValues.

Discuss.”

So, I tried it out. Really special indeed.

Say you had an application with a salesperson form. In this example we have a whopping three documents, but stick with me. We have three fields, “date”, “item” and “quantity”. These three fields are multi-value fields. We’ll assume we have three documents because we only have three salespeople, one for each.

Doc 1:
11/15/09; 11/30/09; 12/15/09; 12/31/09
Apples; Oranges; Grapes; Peaches
10; 30; 40; 20

Doc 2:
11/15/09; 11/30/09; 12/15/09; 12/31/09
Oranges; Apples; Grapes; Peaches
40; 30; 20; 10

Doc 3:
11/15/09; 11/30/09; 12/15/09; 12/31/09
Peaches; Grapes; Apples; Oranges
30; 40; 20; 10

Now if we put these three docs in a view, without “Show multiple values as separate entries”, I would have three rows in my view, with all the data lumped together, separated by semi-colons.

Or I could follow Nathan’s tip and get this:

special.PNG

And then I could use CreateViewNavFromCategory(dateVariable) to get all my column values. Sort of the “GetAllEntriesByKey” version of the NotesViewNavigator, but better. Way better.

*Newbie tip – don’t sort the remaining columns. Notes will screw up the whole “show as multiple values” thing and each sorted column adds rows for each value for each field. Not good.

*Second newbie tip – don’t rely on the view preview in Designer for this type of view. It almost never looks the same in Designer as it does in the client. There is a reason for the “Preview in Notes” button, use it.

Older posts «

» Newer posts