Solved

Sort a list in lotus script

Posted on 2008-10-20
16
2,653 Views
Last Modified: 2013-12-18
I'm working on an action that will take a list of names (obtained from a form) and lookup their associated group. Pull each groupname onto a list (unique names only) then update the group field on the form.

The problem I have is, before I update the group name field I want comapare the new version with the old and alert the user of the change. But the 2 fields have the groupnames in different order. Has anyone written a list compare function that can handle that?

Thx!
0
Comment
Question by:BillTr
  • 8
  • 7
16 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22762739
I must have a sort() function somewhere, but there's an easier solution in R6: use the Evaluate() function. Pass a formula as a string parameter, it returns the output values as an array.

In your case you don't even have to sort, but you might "subtract" both lists (assuming that you don't exchange two groupnames in which case there won't be differences!).

Example:

Dim v As Variant

v= Evaluate(|@Trim(@Replace(FieldWithNewNames;FieldWithOldNames;""))|, doc)
If v(0)="" Then
   ' nothing changed
Else
   'changes!!
End If
0
 

Author Comment

by:BillTr
ID: 22767140
His Sjef,
Did you mean to use @compare? I've been experimenting with this.
DUPCHKLIST is just a comma delimited string that I build. OldList is also a string field, read in from the doc.

Dim v As Variant
DUPCHKLIST = Evaluate(|@sort(DUPCHKLIST;)|)
v= Evaluate(|@Trim(@Compare(DUPCHKLIST;OLDLIST;""))|, doc)
   If v(0)="" Then
        Msgbox "No change"
   Else
       Msgbox "changed"
  End If
0
 

Author Comment

by:BillTr
ID: 22767357
Sjef,
If you can just help me with the sort on the DUPCHKLIST. That should do it.

Thx!
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22767481
Nope, I picked @Replace purposely, I don't need @Compare. But if there's a better function to do it, be my guest. The general idea is to use Evaluate() to solve this type of problems. The example is just that: an example.

The @Replace(l1;l2;"") will replace all list values in l1 that occur in l2 by the empty string. The @Trim(l3) will remove empty strings from the list l3 and leave the rest. If there is no rest, it will leave the empty string as only element.

Of course, there could be mistakes in the code... Warranty up to and including the threshold... :-P
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22767522
Oh, sorry, forgot something: the values should be LISTS. So if you have a string that contains commas, you'd have to @Explode it first.

v= Evaluate(|@Trim(@Replace(@Explode(Dubcek;",");OldNames;""))|, doc)
If v(0)="" Then
   ' nothing changed
Else
   'changes!!
End If

If OldNames is also comma-delimited, put another @Explode(OldNames; ",") instead of it.
0
 

Author Comment

by:BillTr
ID: 22771089
That works great, but can I sort Dupchklist?

Something like:
v = Evaluate(|@Trim(@Sort(@Explode(DUPCHKLIST;","))|,doc)???
0
 
LVL 63

Expert Comment

by:SysExpert
ID: 22771437
http://www-10.lotus.com/ldd/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/c53130426d18db0e85256f7b00571d46?OpenDocument&Highlight=0,group

This is the code sample for the article, "Working with groups in LotusScript."

also read the article itself.


I hope this helps !
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22772530
v = Evaluate(|@Sort(@Explode(DUPCHKLIST;","))|,doc)

The parentheses didn't match, and the @Trim wasn't very useful, so I removed it.
0
 

Author Comment

by:BillTr
ID: 22777333
I keep getting an empty variant.. here is the code I tried.

NEWGROUPlist= Evaluate(|@Sort(@Explode(DUPCHKLIST;";"))|,doc)

NEWGROUPlist= Evaluate(|@Explode(DUPCHCKLIST)|)

DUPCHKLIST is delimited by ;

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22777615
The doc as a parameter is required, the formula interpreter needs to have a context. If there is a field DUPCHKLIST in the doc. So the second will never work, it needs to be

NEWGROUPlist= Evaluate(|@Explode(DUPCHCKLIST)|, doc)

The first one should work, your Notes-version is R6. I hope you didn't have those two calls together in your code?

Maybe use the debugger, so you can step through the code and inspect every variable.
0
 

Author Comment

by:BillTr
ID: 22780177
DUPCHCKLIST (now NEWGROUPstr) is a delimited string I build by pulling data out of a view. There is not a field on the form by that name.

 I changed the name to make the variable type a bit more clear.
NEWGROUPlist= Evaluate(|@Sort(@Explode(NEWGROUPstr;";"))|,doc)
NEWGROUPlist = "" when I run.
NEWGROUPstr = "group1;group2;group3"



0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 250 total points
ID: 22780478
Aaaaah... Me bad.

NEWGROUPlist= Evaluate(|@Sort(@Explode("| + NEWGROUPstr + |";";"))|,doc)

Since Formula doesn't know a thing about NEWGROUPstr, you have to create the complete string first, by embedding the variable's contents, and then call Evaluate.
0
 

Author Comment

by:BillTr
ID: 22780861
Great!

So... another dumb question. Now that I have my list sorted, I want to display it back to the user.
I assume that means a coversion back to the text via an implode, but I get type mismatch when I try that.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22781102
Heh, no, easier: in LotusScript we have Split and Join instead of @Explode and @Implode

Try to set the textfield's value to Join(yourarray, ";")
0
 

Author Closing Comment

by:BillTr
ID: 31508052
Worked great! Thanks again for the help!
You helped me on several things so I increased the points.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22781529
Gweat!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I modify this Excel worksheet with a script? 15 90
Add and format columns in vb6 7 63
VbScript to countdown to New Year's Day 6 65
Convert .csv to tab delimited text 11 36
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question