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 |

3 comments:
And if you used the second part of my last name sorting technique from today for your rejecteds, they could be saved as:
Chris Byrne
Ben Langhinrichs
Rocky Oliver
I love list manipulation as well, and it is fun how these two posts could work together. Cheers!
Neat.
Actually, if all you're trying to do is get out the names of those who approved, there's a much simpler approach than using @Replace (a function I, too, like very much):
@Trim(@Left(Name + "~" + ApprovalStatus; "~Approved"))
Post a Comment