Notes Ninjas Notes Ninjas
Lotus Notes hints, tips, error messages
Arraygetindex

Hint Short Cut: Add this to your code & documentation to help you find this page.
http://www.notesninjas.com/#ArrayGetIndex or http://www.notesninjas.com/A555F9/nn.nsf/ByAlias/ArrayGetIndex


Arraygetindex is a built in lotusscript function that doesn't seem to be used much. There is a quirk.





I was wondering why ArrayGetIndex is not used by developers more.

It basically returns an index number for the position of the value in an array or null if the element does not exist, BUT if the element does not exist ireturns null.

So to test use >=0 or stick isnull( <arraygetindex>)

So how does this work with userroles and roles?

Well you could do a

forall r in roles

if r="[Admin]"  then admin=true

end forall

 

but a quicker way would be

 If Arraygetindex(db.QueryAccessRoles(s.EffectiveUserName),"[Admin]")>=0 Then Msgbox("[Admin] is there")

or to check that Admin is not in the roles

 If Isnull( Arraygetindex(db.QueryAccessRoles(s.EffectiveUserName),"[Admin]") ) Then Msgbox("[Admin] not there")

 

Example code:


Dim s As New notessession
 Dim db As notesdatabase
 Set db = s.currentdatabase
 roles = db.QueryAccessRoles(s.EffectiveUserName)
 Msgbox (Implode(roles,"--"))
 
 If Isnull( Arraygetindex(roles,"[Admin]") ) Then Msgbox("[Admin] not there")
 If  Arraygetindex(roles,"[Admin]")>=0 Then Msgbox("[Admin] is there")

 

 Jump to:     Notes Tips
    Lotus Notes Index 
  Register for Tips
Previous Lotus Notes Tip 
    Next Lotus Notes Tip
Your company logo here?
Adam Foster
Free Cash Making Web Site
Free Revenue Earning Blog Site
 Free Revenue Earning Newsletter Site   
Free Search Pages Free Web stats
Free Contact Us page
Cheap .com domain names
 Need a website or 
   Lotus Notes
  problem solved?
Adam Foster
Web Services Platform Architecture: Soap, WSDL, WS-Policy, WS-Addressing, WS-Bpel, WS-Reliable Messaging and More by Francisco Curbera, Frank Leymann, Tony Storey, Donald Ferguson, Sanjiva Weerawarana
Other books claim to present the complete Web services platform architecture, but this is the first one I've seen that really does. The authors have been intimately involved in the creation of the architecture. Who better to write this book?
See at: Amazon.co.uk | Amazon.com |