Solved

Sort a list in lotus script

Posted on 2008-10-20
16
2,621 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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