[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

question for jerrith (script library)

Posted on 2002-05-01
10
Medium Priority
?
249 Views
Last Modified: 2013-12-18
I created one script library named

 Name : Check_Role

And the code is
Dim roles As Variant
Dim found As Integer
Dim session As  notessession

Sub stat_role
     Set session =New  notessession
Dim user As New NotesName(session.EffectiveUserName)
        roles=Evaluate("@UserRoles")
     found=False
     Forall r In roles
          If r="[Static_Role]" Then
               found=True
               Exit Forall
          End If
     End Forall
     
     If Not found Then
Print "Sorry, " + user.Common + ".[<BR>]You are not  authorized."
     Exit Sub
     End If
     
End Sub

And  script library I am calling in agent like this

and the agent i made as "run agent as web user"  

Use "Check_Role"

        Dim  session As New notessession
     Dim db As notesdatabase
     Dim view As notesview
     Dim doc As notesdocument
     
     Set db = session.currentdatabase
     Set view = db.getview("Qstatic")
     Set doc=view.Getlastdocument


Call stat_role    
Exit Sub

And I have some html code like this
        Print"<html>"
        Print"<head>"
     Print "<title>Dialup MTD</title>"
     Print "<body topmargin="0" leftmargin="0">"
     Print "<div align='center'>"
     Print "<b>Date:"
     Print"<font color='blue'>"&Format(Today, "Medium Date")&"</font></b><br>"
Print “</html>”

Now the problem is if the user is not having role permission its giving proper output like

U r not authorized.

If the user logs who is having the role permission its giving agent done.i don’t know where I am wrong .

0
Comment
Question by:saleemkhan
10 Comments
 

Expert Comment

by:jvanhalderen
ID: 6983404

    If Not found Then
Print "Sorry, " + user.Common + ".[<BR>]You are not  authorized."
    Exit Sub
    End If

change it into:


    If Not found Then
Print "Sorry, " + user.Common + ".[<BR>]You are not  authorized."
    Exit Sub
ELSE
Print "Welcome " + user.common
    End If
0
 
LVL 10

Expert Comment

by:zvonko
ID: 6984246
to jvanhalderen: Are you relative to JM?

to saleemkhan: your Sub stat_role can not abort the processing of calling agent.
Better way would be to make a function.
Like this:
Function stat_role As Integer
  Dim roles As Variant
  Dim found As Integer
  found=False
  roles=Evaluate("@UserRoles")
  Forall r In roles
    If r="[Static_Role]" Then found=True
  End Forall
  If Not found Then
    Dim session As New NotesSession
    Dim user As New NotesName(session.EffectiveUserName)
    Print "Sorry, " + user.Common + ".[<BR>]You are not  authorized."
    stat_role = False
  Else
    stat_role = True  
  End If
End Function

Than you can call it from your Agent like this:
  If (stat_role) Then
   '...your html prints
  End If

Regards,
zvonko

0
 
LVL 8

Accepted Solution

by:
Jean Marie Geeraerts earned 200 total points
ID: 6985691
Hi Saleem,
I noticed you posted a question for the mail you sent me.

So here's my response as given by email:

Well the best way to use the check_role code is to put it in a function and have that function return true or false, depending on the result.

Here's a general setup for your agent :

(Options)
Option Public
Option Declare
Use "Check_Role"

(Declarations)
Dim session as NotesSession

Function Verify_Role(role as string)
     REM Check if the user has the role specified as a parameter and return true or false
     REM Call the function with the role to check as a parameter and include square brackets.
     REM e.g. hasRole=Verify_Role("[Static_Role]")

     Dim roles As Variant
     Dim found As Integer
     Dim user As New NotesName(session.EffectiveUserName)

     roles=Evaluate("@UserRoles")
     found=False
     Forall r In roles
          If r=role Then
               found=True
               Exit Forall
          End If
     End Forall
     Verify_Role=found
End Function

Sub Initialize
     Set session=New Notessession
     Dim user As New NotesName(session.EffectiveUsername)

     If Not(Verify_Role("[Static_Role]")) Then
          Print "You are not authorized to run this agent"
     Else
          Print"<html>"
          Print"<head>"
          Print "<title>Dialup MTD</title>"
          Print "<body topmargin="0" leftmargin="0">"
          Print "<div align='center'>"
          Print "<b>Date:"
          Print"<font color='blue'>"&Format(Today, "Medium Date")&"</font></b><br>"
          Print "</html>"
     End If
End Sub


If you use this body for your agent everything should work fine.
Regards,
JM
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Expert Comment

by:zvonko
ID: 6985697
Here the best example why whisper behind the curtain is no good :)

0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 6985807
OH well,
Saleem can still reject the answer and accept my comment :-)
0
 
LVL 10

Expert Comment

by:zvonko
ID: 6985844
That was not that what I mean.
I mean the delta between email and postings here :-)



0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 6985848
Answer by email is a lot quicker for the questioneer, but if he doesn't say he's posted a question on EE as well, well I don't go look there, you know :)
0
 
LVL 10

Expert Comment

by:zvonko
ID: 6985891
Hey, I am no angel too. I have done this also in former times. Only topic is to be aware of the side effects :-)

0
 

Author Comment

by:saleemkhan
ID: 7005269
Thanks jerrith.
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 7005314
You'r' welcome :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

830 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