Thursday, June 29, 2006

List Manipulation

I love list manipulation. Now we can do so much w/@For and stuff. But in the good ole days, list manipulation was, as Rocky would say, "Kewl"..

List manipulation gives a programmer the ability to simulate arrays and "looping" that used to not be available to Notes Developers. List manipulation is still very useful, and fast. It may be "Cheesy", but I sometimes use it in script w/Evaluate statements.

Here is a something I do all the time..

Lets say you had two fields..

In one field, we'll call Name, we have "Andre Guiard" : "Ben Langhinirichs" : "Chris Byrne" : "Henry Newberry" : "Rocky Oliver"
In the second field, we'll call ApprovalStatus, we have "Approved" : "Rejected" : "Rejected" : "Approved" : "Rejected"

The fields corresponde, so Andre approved the request, Ben and Chris Rejected the request, Henry approved, and finally Rocky Rejected the request.

In a third field, Approvers, we want to list the names of the people who approved, and in a fourth field, Rejecters, we want to list all the names of the people who denied the request.

This is easy with list manipulation:

source := Name + "¥" + ApprovalStatus;
approvalList := Name + "¥" + "Approved";
rejectList := Name + "¥" + "Rejected";
Field Approvers := @Word(@Trim(@Replace(source;rejectList;""));"¥";1);
Field Rejectors := @Word(@Trim(@Replace(source;approvalList;""));"¥";1);

The formula to populate the Approvers field, uses the @Replace function. From the Help database:

@Replace( sourcelist ; fromlist ; tolist )
Parameters
sourcelist
Text list. The list whose values you want to scan.
fromlist
Text list. A list containing the values that you want to replace.
tolist
Text list. A list containing the replacement values.

In our formula, we are comparing the source list to the rejectList, anywhere there is a match, it is replaced with "". Then @Trim is used to remove those null values from the list, and we are left with just Andre Guiard¥Approved and Henry Newbery¥Approved. Then the @Word function is used to parse out just the name part of the list.


Source
rejectList- From
to
Results
Andre Guiard¥Approved
Ben Langhinrichs¥Rejected
Chris Byrne¥Rejected
Henry Newberry¥Approved
Rocky Oliver¥Rejected
Andre Guiard¥Rejected
Ben Langhinrichs¥Rejected
Chris Byrne¥Rejected
Henry Newberry¥Rejected
Rocky Oliver¥Rejected
      ""
Andre Guiard¥Approved
Henry Newberry¥Approved

To populate the Rejectors field, we use the @Replace function again, this time, the From parameter is set to approvalList. And again, the @Word function to parse out just the name portion of the list.


Source
approvalList- From
to
Results
Andre Guiard¥Approved
Ben Langhinrichs¥Rejected
Chris Byrne¥Rejected
Henry Newberry¥Approved
Rocky Oliver¥Rejected
Andre Guiard¥Approved
Ben Langhinrichs¥Approved
Chris Byrne¥Approved
Henry Newberry¥Approved
Rocky Oliver¥Approved
      ""
Ben Langhinrichs¥Rejected
Chris Byrne¥Rejected
Rocky Oliver¥Rejected

Wednesday, June 28, 2006

How to know if a User has access to a database..

I had a little action link on a form that allowed users to populate a field from a picklist. The data used for populating could come from two different data sources. If a user had access to a certain database, I wanted to display a picklist to data from that database, but if they didn't have access, then I wanted to display a picklist to data from a database that all users in our company have access to..

At first I tried to do If db.IsOpenByReplicaId.. I figured if it didn't open, then I would use the other db. But it gave an error when users who didn't have access to the database ran the code.

So, I wrote a function to trap the error. This little function will come in handy to lots of you I'm sure..

Here it is..

Function DBOpenByReplicaIDSafe(db As notesdatabase, Byval strServer$, Byval strRepID$) As Boolean
On Error 4060 Goto returnFalse
' generally better to find out exact error number, as opposed to ignoring unexpected errors that might not represent the type of failure you were expecting.
DBOpenByReplicaIDSafe = db.OpenByReplicaId(strServer, strRepID)
DBOpenByReplicaIDSafe = True
Exit Function
returnFalse:
DBOpenByReplicaIDSafe = False
Exit Function
End Function

Tuesday, June 27, 2006

My first posting...

Hi.. I hope to share tips and tricks I have learned during my 14 years of Notes development.

Here is my first tip:


It returns a list of fridays .. I used -7 in the temp variable, so it gives me the past 10 fridays for user to pick from..

To change the day of the week the list represents, change the avalue variable and the -7 in the temp variable...

a:= @Weekday(@Today);
avalue:= 5 - a;
firstvalue := @Adjust(@Today;0;0;avalue;0;0;0);

temp := firstvalue;
@For(n := 1; n <= 10; n := n + 1;
temp := temp : @Adjust(temp[n];0;0;-7;0;0;0));
@Trim(@Text(@Sort(temp;[Descending])))