Solved

Sort a list in lotus script

Posted on 2008-10-20
16
2,579 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now