We help IT Professionals succeed at work.

LotusScript:  problem using Evaluate statement.

pentapod
pentapod asked
on
1,178 Views
Last Modified: 2013-12-18
I have a form with 6 fields, called
Approver_1
Approver_2
Approver_3
etc.

When I put test fields on the form I can see that

@Member(@UserName;Approver_1:Approver_2:Approver_3:Approver_4:Approver_5:Approver_6)

gives exactly the right results... ie if the user's name is Approver_3, then it returns "3".

I have an action button, behind which is various script including:

Dim Authorized As Variant
...
Authorized=Evaluate("@Member(@UserName;Approver_1:Approver_2:Approver_3:Approver_4:Approver_5:Approver_6)")

However, the Evaluate statement above doesn't work.  No matter what, I get Authorized(0) = 0.

What am I doing wrong??

...Pentapod
Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
OK, I changed the code to:

     Dim session As New NotesSession
     Dim ws As New notesuiworkspace    
     Dim db As NotesDatabase
     Dim uidoc As notesUIDocument
     Dim approverlist As String
     Dim Authorized As Variant

     Set uidoc=ws.currentDocument

Approverlist = uidoc.fieldgettext("approver_1") + ":" + uidoc.fieldgettext("approver_2") + ":" +uidoc.fieldgettext("approver_3") + ":" +uidoc.fieldgettext("approver_4") + ":" +uidoc.fieldgettext("approver_5") + ":" +uidoc.fieldgettext("approver_6")
         Authorized=Evaluate("@Member(@UserName;'"+ Approverlist +"')")

.... It doesn't give an error, but it still doesn't work.  I can see that Approverlist contains my hierarchical name, as well as others separated by :s, but Authorized(0) = 0.

Any thoughts?

....Pentapod
Simply Pentapod,
The Approvelist is not a real LIST to Notes the way you created it.  Use this:

Authorized=Evaluate("@Member(@UserName; @Explode('" + Approvelist + "';':'))")

-Gus

Author

Commented:
Do I need to change the creation of Approverlist?  Because it still isn't working... sigh...  :(

My Approverlist looks like this:

"Pentapod/BR/SPE:Fred Bloggs/BR/SPE:John Doe/UK/EU/SPE:::"

My @username is Pentapod/BR/SPE

....Pentapod
@username returns the full heirarchical name, its not returning 'Pentapod/BR/SPE'!  Are you sure that 'Pentapod/BR/SPE' is stored in the field (in that exact syntax) on the form?  If it is then in the formula change from @username to @v3username.

-Gus

Author

Commented:
Oh - you're right!

OK, using
     Authorized=Evaluate("@Member(@name([CN];@UserName); @Explode('" + Approvelist + "';':'))")

and changing Approverlist so that it uses CN format only, it still doesn't work though...

Maybe there's a better way of going about this.  All I want to know is how, using LotusScript, to tell whether the current user is one of the users listed in the fields on the form.

Pentapod

This is the simplest of ways!  Why you want to complicate things with script?

Just tell me whats the formula in the field, or give me a sample field value...the formula that fills approver_1 for instance.

-Gus

Author

Commented:
There is a form that the user creates, to request equipment purchase.  The user fills in the equipment details and prices, and then lists the names of the approvers in the fields Approver_1, Approver_2, etc.  The number and names of the approvers vary depending on what equipment is being purchased and for who, so this information can't be fixed.

Then the user presses a "send to approvers" action button and the database sends an email to the first approver with a doclink.  The first approver goes to the document and clicks on an "approve" or "reject" action button at the top.

The Approve button has to: 1. check that the user who clicked it is one of the approvers listed;  2. stamp "approved" with the date and time if the user is an approver; 3. find the next approver (if there is one) and send an email with doclink; and 4. check to see if that was the last approver, and if so, change the status to "approved" and notify the initiator of the request.

Right now I have got it to work by doing it another way.

     approver(0) = uidoc.fieldGetText("Approver_1")
     approver(1) = uidoc.fieldGetText("Approver_2")
     approver(2) = uidoc.fieldGetText("Approver_3")
     approver(3) = uidoc.fieldGetText("Approver_4")
     approver(4) = uidoc.fieldGetText("Approver_5")
     approver(5) = uidoc.fieldGetText("Approver_6")
     
     For i = 0 To 5
          If currentuser(0) = approver(i) Then
               Authorized = 1
          End If
     Next


Still, it would be nice to know how to manipulate a list using script.

....Pentapod
There is a whole section in the help file on Lists.  Its really simple, a list is associated with an array.  But when you get a value from the ui with fieldgettext, u will get a string value.  You should use the backend and u will capture the list in an array eg item=doc.approver_1, now item will be an array.  You can use a forall loop or a for loop to traverse the array.  For assigning, use doc.replaceitemvalue("approver_1",array).  Thats a short description.

-Gus

Author

Commented:
Don't have time to try it at the moment, but I'm accepting your answer as I'll be travelling for the next 3 weeks.  I'll check it all out when I get back.  Anyway the database is working with the work-around so it's no longer urgent.  Thanks for the help,

Pentapod

Author

Commented:
Don't have time to try it at the moment, but I'm accepting your answer as I'll be travelling for the next 3 weeks.  I'll check it all out when I get back.  Anyway the database is working with the work-around so it's no longer urgent.  Thanks for the help,

Pentapod
Good luck

-Gus

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.