Solved

question for jerrith (script library)

Posted on 2002-05-01
10
225 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 50 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

789 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