Solved

Sort a list in lotus script

Posted on 2008-10-20
16
2,521 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

15 Experts available now in Live!

Get 1:1 Help Now